2
votes

I'm using laravel 5.3 and using Multi-Auth Hesto Package. I used view composers to pass my current Auth::user to Welcome.blade

I already logged in my Customer/Home.blade but when I go to Welcome.blade and accessing the current Auth::useran error says "Trying to get property of non-object"

Here's my Viewmcomposers/AuthComposer.php

class AuthComposer
{
    public $currentUser;

 public function __construct()
    {
        $this->currentUser = Auth::User();
        View::share([ 'currentUser' => $this->currentUser ]);
    }

   public function compose(View $view)
    {
        $view->with('currentUser', Auth::user()->name);
    }
}

App/Providers/ComposerServiceProvider.php

 public function boot()
    {

    view()->composer('welcome', function ($view) 
    {
        $currentUser = Customer::where('name', Auth::user()->name);
        $view->with('welcome', $currentUser );    
    }); 
    }

Config/App.php

 App\Providers\ComposerServiceProvider::class,

My routes for customer

Route::get('/home', function () {
    $users[] = Auth::user();
    $users[] = Auth::guard()->user();
    $users[] = Auth::guard('customer')->user();
    return view('customer.home');
})->name('home');

And I just call this in my routes/web.php for my welcome.blade

Route::get('/', 'WelcomeController@showWelcome');
1
any stacktrace - that pile of function calls that shown when laravel went wrong? - Bagus Tesa
I updated my question and my line 18 would be this $view->with('currentUser', Auth::user()->name); But when I remove the ->name it shows nothing. Welcome.blade sees me as a guest - Ylla
well, try to put dd(Auth::user()) just before your line 18 in ComposerServiceProvider.php, i wonder if the user actually never auntheticated and Auth::user() returns null. - Bagus Tesa
it returns 'null' - Ylla
ugh, well, how did you handle user login? - Bagus Tesa

1 Answers

0
votes

Use Auth;

in top of page it may help you.

Show me complete error .