Home > other >  How to send to laravel request with api prefix?
How to send to laravel request with api prefix?

Time:10-07

location @laravelapi {
        rewrite /api/(.*)?$ /api/index.php?$is_args$args last;
}

When we try access to api/routeexample, laravel gets only routeexample part, and throws 404 error. How we can send full url including 'api' part?

CodePudding user response:

location @laravelapi {
        rewrite /api/(.*)?$ /api/index.php?api$is_args$args last;
}

It seems like the easiest way, but i dont think that it is the best practice.

CodePudding user response:

I m adding an example of how we define route for API request:

In routes/api.php

Route::group(['prefix' => 'v1'], function () {
Route::post('api_request', [App\Http\Controllers\YourController::class, 'targeted_function_name'])->name('api_request');

});

  • Related