View Composer - how to pass complete collective through ?

Posted 11 months ago by gr8h8m

So i'm trying to pass data to my sidebar on all pages for menu

Menu class:

class Menus extends Model {

    protected $table = 'menus'; protected $fillable = ['title','parent_id'];

    public function parent() {

         return $this->hasOne('App\Menus', 'id', 'parent_id')->orderBy('order'); 
    }

    public function children() { 
        return $this->hasMany('App\Menus', 'parent_id', 'id')->orderBy('order'); 
    }
 }

using ComposerServiceProvider to pass data to View

view()->composer('backend.includes.sidebar', function ($view) {

         $view->with('menus', \App\Menus::where('parent_id', 0)->orderBy('order')->get());

});

Ger error: Property [children] does not exist on this collection instance

How can i pass a complete collective (all menu and submenu items from database) to a view using a view composer so the menu appears on all pages

have got it working fine on one page, but that was not using a view composer to pass data.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.