T
T
TERRAN472016-07-09 12:13:06
Laravel
TERRAN47, 2016-07-09 12:13:06

Where can I use Auth::user() in LARAVEL5?

how can I use Auth::user() in particular, I need it in AppServiceProvider or in routes

public function boot()
    {
        $userId = Auth::user()->id;
        dd($userId);   
        $categories = Catigories::where('user_id','=',$userId)->get();
        view()->share('categories', $categories);                   
    }

the task is to display a variable for all views and sorted by the authorized user,
the problem is that he does not see Auth::user() Trying to get property of non-object

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-07-09
@TERRAN47

the problem is that he does not see Auth::user() Trying to get property of non-object
He sees everything perfectly . It's just that the user is not authorized, so it's impossible to get his id. Use Auth::check() first to check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question