Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Smashing's avatar

Api routes and make db query with custom tools

Hi,

I  do not quite understand what are exactly and how api routes works in Laravel and how we can do database queries when we are creating our personal custom tools (https://nova.laravel.com/docs/3.0/customization/tools.html) .

Maybe can someone explain it to me?

0 likes
2 replies
bobbybouwmann's avatar

Well, it basically means you can define your own routes in routes/api.php. In that route, you can connect your own controller which can be used inside your tool.

Here is an example

// routes/api.php

Route::get('download-excel', [ExcelController::class, 'download'])->middleware('nova');

// app/Http/Controllers/Api/ExcelController.php
class ExcelController extends Controller
{
    public function download(Request $request)
    {
        // Do whatever you want here
    }
}

In your tool, you can then use the URL you created in your API routes

1 like
Smashing's avatar

And the controller is the same on we use when we are using web routes, right? Second question is we need to put the middleware('nova') when we are creating a api route, and why

Please or to participate in this conversation.