我有三个表,分别是住宿,房间和 accommodation_rooms 。
在房间中,我具有id和room_name字段,以及时间戳创建/修改的字段和其他设置字段。
第三个表是外部参照表,具有两个 accomodation_id 和 room_id 字段。
如此处所述:https://laravel.com/docs/5.7/eloquent-relationships#many-to-many我在住宿模型中明确设置了Rooms方法:
public function rooms()
{
return $this->belongsToMany('App\Models\Room', 'accomodation_rooms', 'accomodation_id', 'room_id');
}
然后我尝试设置如下字段:
$room = [
[ // Select2Multiple = n-n relationship (with pivot table)
'label' => "Rooms",
'type' => 'select2_multiple',
'name' => 'rooms', // the method that defines the relationship in your Model
'entity' => 'rooms', // the method that defines the relationship in your Model
'attribute' => 'room_name', // foreign key attribute that is shown to user
'model' => "App\Models\Rooms", // foreign key model
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
]
];
$this->crud->addField($room);
但是我在vendor / backpack / crud / src / PanelTraits / Fields.php,第37行上收到以下错误:
未定义索引:名称
我有以下代码:
// if the label is missing, we should set it
if (! isset($completeFieldsArray['label'])) {
$completeFieldsArray['label'] = mb_ucfirst(str_replace('_', ' ', $completeFieldsArray['name']));
}
请帮助。
Laravel 5,7,背包式Laravel 3.5。
答案 0 :(得分:0)
我终于得到了我输入错误的错误。 字段定义数组应该是一个更简单的数组,没有一级方括号。
option