I followed the instructions to setup and install Laravel Breeze and it worked to the extent that I could register a user and subsequently log in, so that's cool.
What I'm struggling to get working is to set up my API routes to only be accessible when a user is logged in.
In my api.php file, I have this route set up to return ["message" => "success"]
which I can access at /api/test
if I remove the middleware wrapper. I have tried putting in various things in the below middleware bit - ['auth']
, ['auth.api']
etc but nothing seems to work. Some middleware 'passes' but inside my TestController, if I dump Auth::user(), I get null.
Route::middleware( ?? what goes here ??)->group(function () {
Route::get('test', TestController::class);
});
This is my guards file, I copied the API section from stackO.
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'session',
'provider' => 'users',
'hash' => false,
],
],
Any assistance would be welcomed, thank you