I have 'Menus' table and this website is for a restaurant. When I add a new record through Laravel Backpack Crud, it gives me an error
BadMethodCallException Call to undefined method App\Models\Menu::menu()
however, it adds the record to DB. When I want to update some record, it gives me this error but does not update the DB. Where can be the problem?
Here is my model:
<?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');