Configuring Routes

Editing Route Prefix

When installing the package using the installation command, the routes/api.php file changed and at the end of the file the following lines of code were appended.

Route::prefix('/aap')->group(function () {

In order to avoid naming conflicts with existing API routes, the Api Auto Pilot routes are wrapped with an /aap prefix. As you can guess, you can change the prefix, or even remove it, if there is no use for your project. The Package's middleware is already applied to all existing API routes, to avoid deletes by mistake.

Using Authentication Middlewares

You might want to authenticate the requests that are being made to your API.That's something Laravel Sanctumopen in new window or Laravel Passportopen in new window, could do. So to enforce authenticated request you can just chain the middleware('auth:santum') method to the Api Auto Pilot Route group, and you are all set! so the Route Group would look something like this.

//routes/api.php - with Laravel Sanctum authentication
Route::prefix('/aap')->middleware('auth:sanctum')->group(function () {

Easy, right?

Overriding the package's routes

To override an existing Api Auto Pilot route, make sure to write your custom route, above the package's routes declaration as shown in the below.

Route::post('my/custom/model/creation/route', function(Request $Request){


Route::middleware('auth:sanctum')->prefix('/aap')->group(function () {


Generally, it would be a good idea to disable the endpoint that you override, to avoid having duplicate routes, that could result in a security breach for your application
See more at Enabling/Disabling Endpoints section.

Last Updated:
Contributors: GeorgeFourkas