我有“菜单”表,该网站用于餐馆。当我通过Laravel Backpack Crud添加新记录时,它给我一个错误
BadMethodCallException调用未定义的方法 App \ Models \ Menu :: menu()
但是,它将记录添加到DB。当我想更新某些记录时,它给了我这个错误,但没有更新数据库。问题出在哪里?
这是我的模特:
<?php
namespace App\Models;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\Model;
class Menu extends Model
{
use CrudTrait;
protected $table = 'menus';
protected $fillable = ['image', 'name', 'description', 'price', 'category_id', 'popular'];
public function category()
{
return $this->belongsTo(Category::class);
}
Category.php:
<?php
namespace App\Models;
use Backpack\CRUD\CrudTrait;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
use CrudTrait;
protected $table = 'categories';
public function menu()
{
return $this->hasMany(Menu::class);
}
MenuCrudController:
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\Menu');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/menu');
$this->crud->setEntityNameStrings('menu', 'menus');