我有三个表,住宿,客房和住宿房间。
在房间我有ID和ROOM_NAME领域,具有时间戳创建/修改的字段和其他领域设置在一起。
第三个表是外部参照表,与两个accomodation_id和ROOM_ID领域。
在我的住宿模型明确https://laravel.com/docs/5.7/eloquent-relationships#many-to-many设置我的房间方法:按如下说明:
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);
但我得到的供应商/背包/污物/ 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,backpackforlaravel 3.5。
我终于得到了我的打字错误错误。字段定义阵列应该是较简单的一个,方括号的一个级别。
$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?
];