How can I recreate this? I am new to Laravel, and I have set up a Route::apiResourcepost
data from my vue pages to my controller. I know that I need to protect the API resource and am trying to build an understanding as to how. In api.php, the following works:
Route::apiResource('name', 'App\Http\Controllers\MyController');
But when I try to protect the route with middleware like so:
Route::middleware('auth:api')->apiResource('name', 'App\Http\Controllers\MyController');
I get status 401 unauthorized back, and the response is:
{"message":"Unauthenticated."}
Any feedback as to what I am doing wrong/should be doing would be appreciated.
When you are working with the auth:api middleware, you have to pass a Bearer Token for Authentication in your headers.