Php LAVEL手动更改轴值
我有一个存储统计数据的模型容量。一个容量属于0到多个模型运算符。当某些容量没有任何运算符时,我无法显示用于输入数据的表单。当没有运算符时,我需要显式地将$operator->id设置为0。 不幸的是,我在pivot表中存储了一个容量的操作符列表,我不知道如何模拟它 在我的能力模型中,我有:Php LAVEL手动更改轴值,php,laravel,pivot,relationship,laravel-5.2,Php,Laravel,Pivot,Relationship,Laravel 5.2,我有一个存储统计数据的模型容量。一个容量属于0到多个模型运算符。当某些容量没有任何运算符时,我无法显示用于输入数据的表单。当没有运算符时,我需要显式地将$operator->id设置为0。 不幸的是,我在pivot表中存储了一个容量的操作符列表,我不知道如何模拟它 在我的能力模型中,我有: public function operators() { return $this->belongsToMany('App\Models\Operator', 'capacity_opera
public function operators() {
return $this->belongsToMany('App\Models\Operator', 'capacity_operator_relation')
->withPivot('id')
->withTimestamps();
}
在我的刀片模板中,我有以下检查:
@if(!$capacity->operators)
// here i need to set an array with one operator, which id = 0
$operator->pivot->id = 0;
@endif
@foreach($capacity->operators as $operator)
<input type="hidden" name="operator" value="{{ $operator->pivot-id }}">
@endforeach
@if(!$capacity->operators)
//这里我需要用一个操作符设置一个数组,id=0
$operator->pivot->id=0;
@恩迪夫
@foreach($capacity->operators as$operator)
@endforeach
也许这会有帮助:
@if(!$capacity->operators)
@foreach($capacity->operators as $operator)
<input type="hidden" name="operators[]" value="{{ $operator->pivot-id }}">
@endforeach
@else
<input type="hidden" name="operators[]" value="0">
@endif
@if(!$capacity->operators)
@foreach($capacity->operators as$operator)
@endforeach
@否则
@恩迪夫