Laravel 5.4 Passport log user action (optional auth: api)
I am using Laravel Passport ( auth:api
), everything works well, however I came up with the idea to register user request records along a specific route.
When a request GET
is made to /movie/65
, I would like to save in movie_view
the following data: user_id
, movie_id
(if the user is logged in)
However, in my controller, I cannot call $request->user()
without installing middleware auth:api
.
What is the best practice you recommend to achieve this goal?
source to share
The default authentication type should be set to 'api' in config/auth.php
Source: https://laracasts.com/discuss/channels/general-discussion/optional-authentication-for-api?page=0 (was very hard to find)
source to share