I am using Sentinel in Laravel 5.4. What I am trying to do is: get logged user detail but Sentinel::getUser()
returns null. For this process, I have seen this instruction in this answer
. I am following using View Composer
method.
Steps I have done
I have created a file ViewComposerServiceProvider
inside Providers
folder. It looks like:
public function boot()
{
$user = Sentinel::getUser(); //<<-- main error: dd($user) returns empty
$userDetail = UsersDetail::where('user_id', $user->id)->firstOrFail();
if ( is_null ($userDetail) ) {
$userDetail = new UsersDetail;
}
view()->composer('backend.*', function($view) {
$view->with('userDetail', $userDetail);
//$view->with('userDetail', 'Test'); //this works fine
});
}
Then, I register this provider in config/app.php
Providers array as
App\Providers\ViewComposerServiceProvider::class,
When, I pass other variables in userDetail
, it's working perfectly. But, I cannot get the logged in user detail. Am I missing something?
Following the first solution from this answer also seems not working since, construct are run prior to the Middleware. Any help please.