У меня проблема с отношениями в Laravel / с Рюкзаком для Laravel.
Эта программа предназначена для создания меню ресторана моего отца.
У меня есть эти таблицы:
- dishes (Table with the Names of the Dishes)
-- id (auto inc)
-- menuname (Name of the Dish)
- weeklymenues
-- id (auto inc)
-- start_date (Monday of the selected week)
-- end_date (Friday of the selected week)
-- menu_monday (There should be the id of the dish)
-- menu_tuesday (...)
-- menu_wednesday (...)
.....
Как я могу сделать это правильно?
В контроллере CRUD я устанавливаю поле:
$this->crud->addField([
'label' => "Monday",
'type' => 'select2',
'name' => 'menu_mondy', // the db column for the foreign key
'entity' => 'menu', // the method that defines the relationship in your Model
'attribute' => 'menuname', // foreign key attribute that is shown to user
'model' => "App\Models\Menu" // foreign key model
]);
И в модели меню я установил это соотношение:
public function menu() {
return $this->belongsTo('\App\Models\Menu');
}
Каждый раз, когда я хочу сохранить CRUD, программа хочет сохранить что-то в таблице блюд:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dish_id' in 'field list' (SQL: update `weeklymenues` set `dish_id` = 1, `weeklymenues`.`updated_at` = 2019-06-25 14:13:14 where `id` = 15)
Что я делаю не так? Как я могу установить правильные отношения?
Заранее спасибо !!