How to access JWT from laravel blade?

2019-09-06 06:20发布

问题:

I'm using JWT (Json Web Token) auth in my Laravel 5.2 app. How can I get user_id from the token inside JavaScript tags in my blade ??

回答1:

You can use JWTAuth like Auth:

After you authenticate, get the user

$user = JWTAuth::user();

then pass data to view:

return view('posts', ['user' => $user]);

and you can use the data in blade:

{{ echo $user->id; }}