Try changing:
class MenusController extends \BaseController {
to
class MenusController extends Controller {
Unless I'm missing something.
You're mixing singular/plural in your models. If a Menu can have one parent, tell it that and name it as such, if a Parent can have many Menus, then name it and make it as such.
Right now you have a Menus
model which should be named Menu
, then in Parent
you name the function menus
, but tell the relation you expect it to have one menu
. Do not mix plural/singular and make sure everything matches the name of your model to work smoothly.
public function parent(){ //->relationship name, important
return $this->hasMany('Parents'); //->model name, not important
}
If you want to eager load it then use
::with('parent')->...
I'm trying to save parent into the menus table. Parent references the id of the menu.
Isn't
::with('parent')->
a way to display menus with a parent?
I managed to fix my problem with saving 'parent' into the database. All I did was changed the column 'parent' to 'parents' in my database and change it from 'parent' to 'parents' in my protected $fillable array.
Your problem was eager loading non-existing relation (with('Parents')
).
Also I'm retty sure an entry doesn't hasMany
parents, but rather belongsTo
a single parent.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community