Answer the question
In order to leave comments, you need to log in
How to use Auth in Laravel Service Provider?
Connecting to the AppServiceProvider with the use Auth method doesn't help. Auth::user() returns NULL when requested. What is the problem?
Answer the question
In order to leave comments, you need to log in
And why, in fact, use the Auth class in the service provider?
Sessions are not available there, and even more so the Auth class (which is a little more than completely zavazed on them).
If your goal is to initially perform certain manipulations with the user to display data in the view, use the view composer.
view()->composer('*', function($view) use ($auth) {
$currentUser = $auth->user();
// делайте что душе угодно, и передавайте переменной во все view
$view->with('currentUser', $currentUser);
});
perhaps a syntax error, use: https://github.com/barryvdh/laravel-ide-helper
he will substitute all use.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question