I’m trying to use simple laravel api for getting and sending requests, after define this api routes in api.php
:
Route::prefix('Api/v1')->group(function () { Route::any('login', 'Apiv1AuthController@login'); Route::any('register', 'Apiv1AuthController@register'); });
and creating AuthController in app/http/controller/Api/v1
directory:
class AuthController extends Controller { public function login() { dd(request()->all()); } public function register() { dd(request()->all()); } }
i get 404
error on this link:
http://127.0.0.1:8000/Api/v1/login
how can i resolve this problem?
Advertisement
Answer
Routes in api.php
are automatically prefixed with /api
. Currently, your routes are:
http://127.0.0.1:8000/api/Api/v1/login http://127.0.0.1:8000/api/Api/v1/register
So navigating to http://127.0.0.1:8000/Api/v1/login
is a 404.
If you remove /Api
, and just use Route::prefix('/v1') ...
then you should have no issue.
Also, always double check your routes with php artisan route:list
to see what’s wrong.