Search code examples
ajaxlaravel-5.3sentinel

ajax call Sentinel::check() always return null


I using Sentinel package, Everything is fine, But when I want call Sentinel::check() and Sentinel::getUser() using ajax, it return null. help me please :(

$currentUser = Sentinel::getUser();
$my_id = $currentUser->id;
return $my_id;

Solution

  • I used another way. First add user's info into a session after logging

    Session::put('city_id', $currentUser->city_id);
    

    then goto app/Http/Kernel.php and active session on rest api routes

    'api' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Session\Middleware\StartSession::class, 'throttle:60,1', 'bindings', ],
    

    and use it in ajax call.