I'm trying to make an api route that's only accessible if the user making the request is logged in. This is what I have in my routes/api.php
but it returns {"error":"Unauthenticated."}
Route::group(['middleware' => ['auth:api'], function () {
Route::post('schedules', ['uses' => 'Api\ScheduleController@store']);
});
Can this be done without laravel passport and how? I only need the route for in-app use for logged in users.
I assumed the login mentioned is on "web" which using "session" as driver.
Your are getting this issue because "web" and "api" guard is using different driver for authentication. Take a look in config/auth.php
. The "api" guard is using "token" as it's default driver.
Thus, you have few options to encounter this.
_token
parameter), unless you are using laravel axios