warpig's avatar
Level 12

How does invokable controllers work?

I want to use an invokable controller that I just made, defined in the routes:

    Route::get('AbilitiesRoleController');

But I can see that the string on top:

use App\Http\Controllers\AbilitiesRoleController;

Is greyed out, which means the routes is ignoring that controller so how can I use it?

0 likes
2 replies
warpig's avatar
Level 12

I wish to use it on a form so I'd prefer it if I could use a method (I have a doubt, I don't know if I need to use the __invoke method only when you have an invokable controller) so that I can pass that into my form's action, how can I do that?

Also the Laravel documentation doesn't cover invokable controllers, searched "invokable" on the search bar but I don't think it returned anything regarding this. Its here: https://laravel.com/docs/8.x/controllers#single-action-controllers

warpig's avatar
warpig
OP
Best Answer
Level 12

Here it is:

When registering routes for single action controllers, you do not need to specify a controller method.

use App\Http\Controllers\ProvisionServer;

Route::post('/server', ProvisionServer::class);
1 like

Please or to participate in this conversation.