Check things in your network tab.
Laravel GET Endpoint Returns 404 Error Despite Existing Route: Trouble with URL Parameters
Hello All.
I've a problem with an endpoint in laravel because I get 404 route not found but the route exists! This is how I run the endpoint:
But if I run
GET https://xxxxxxxxxxxxxx/public/api/v0/authentication/atp/getToken
I get
{
"error": "The age field is required. (and 1 more error)"
}
So It looks like the problem it's because I send the age and code through the url but it's a get method endpoint so there must not be a problem there. Also running
php artisan route:list
at console I get: ...... //others routes GET|HEAD api/v0/authentication/atp/getToken ...................................... AuthController@getValidationAfip GET|HEAD api/v0/authentication/atp/getUrl ............................................... AuthController@getUrlAfip GET|HEAD api/v0/authentication/antex/getToken .................................... AuthController@getValidationAnses GET|HEAD api/v0/authentication/antex/getUrl .. ........
This is the api.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers;
use Illuminate\Support\Facades\DB;
/*
Others routes
*/
Route::prefix("/v0/authentication")->controller(Controllers\AuthController::class)->group(function () {
Route::middleware(['auth:authentication'])->get('/atp/getUrl',[Controllers\AuthController::class, 'getUrlAtp']);
Route::middleware(['auth:authentication'])->get('/atp/getToken', [Controllers\AuthController::class, 'getValidationAtp']);
Route::middleware(['auth:authentication'])->get('/antex/getUrl',[Controllers\AuthController::class, 'getUrlAntex']);
Route::middleware(['auth:authentication'])->get('/antex/getToken', [Controllers\AuthController::class, 'getValidationAntex']);
});
This is the controller method:
public function getValidationAtp(Request $request): \Illuminate\Http\JsonResponse
{
try {
$request->validate([
'age' => 'required|numeric|regex:/^[0-9]{11}$/',
"code" => "required|string",
]);
dd($request->cuil);
//..there is more code but I even not get the dd return
}
Please or to participate in this conversation.