A
A
Alexander Zaika2016-06-24 01:33:38
Laravel
Alexander Zaika, 2016-06-24 01:33:38

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

2 answer(s)
A
Andrzej Wielski, 2016-06-24
@KlassTDevelop

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);
    });

N
Nikolai Shvetsov, 2016-06-24
@ShNn

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 question

Ask a Question

731 491 924 answers to any question