Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 1 year ago.
0

Try changing:

class MenusController extends \BaseController {

to

class MenusController extends Controller {

Unless I'm missing something.

0

Nope that didn't work

0

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.

0
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')->...
0

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?

0
Solution

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.

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

shiva shiva Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.