What do you have in your api middleware? Also how is your routes.php file included?
Can you paste the RouteServiceProvider where the routes.php is registered, and the api middleware as well ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am working with laravel 5.4 to on a custom package. I have defined my routes on a seperate file routes.php. I am loading the routes file through a service provider.
The problem I am facing is that when I send POST requests to the routes the routes are working fine, but when I send GET requests, it redirects me to the login page.
Route::group([
'prefix' => 'api',
'middleware' => 'auth:api',
function(){
Route::get('/users',function() {
$users = \App\User::all();
return response()->json($users);
});
Route::post('/users',function() {
$users = \App\User::all();
return response()->json($users);
});
});
I am using POSTMAN to test my routes.
Please help.
What do you have in your api middleware? Also how is your routes.php file included?
Can you paste the RouteServiceProvider where the routes.php is registered, and the api middleware as well ?
Please or to participate in this conversation.