caffeinated / menus

:pushpin: Menu generator package for the Laravel framework
https://caffeinatedpackages.com
132 stars 59 forks source link

adding ID to route #1

Closed illuminate3 closed 9 years ago

illuminate3 commented 9 years ago

hmmm, this doesn't seem possible.

->add('view profile', 'profiles'. Auth::user()->id )

Or am I doing something wrong again?

kaidesu commented 9 years ago

There's a few quirks I'm working out, so I wouldn't be surprised if its a legit bug right now.

Also, looks like you need a trailing slash after profiles?

use Auth;
use Menu;

...

Menu::make('example', function($menu)) {
    $menu->add('View Profile', 'profiles/'.Auth::user()->id);
});

And be sure to check if you're logged in first, otherwise Auth::user() will return null.

illuminate3 commented 9 years ago

@bugs figured as much, however, this package is another of yours I'm all over :smile:

@error I have the Auth::user()->id displaying on the same page, so not a null situation.

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;

use Auth;
use Menu;

class MenuServiceProvider extends ServiceProvider {

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Menu::make('public', function($menu) {
            $menu->add('Rakko', 'welcome');
            $menu->add('Profiles', 'profiles');
//          $menu->add('View Profile', 'profiles/'.Auth::user()->id);
//          $menu->add('view profile', 'profiles'. Auth::user()->id );
        });
    }

I don't have a register method.

Error:

Trying to get property of non-object
kaidesu commented 9 years ago

I'll be sure to look into this!

kaidesu commented 9 years ago

I believe this is simply due to the loading order of service providers. If you die and dump the result of Auth::user() you'll find that it is null (thus, the Trying to get property of non-object error). The session data is not loaded until after all service providers have booted.

See the following forum threads for more information:

IndraGunawan commented 9 years ago

What is the solution for this problem?