Yes, you can create an invokable controller without the $request parameter by using the __invoke method in the controller class. Here's an example of how to create an invokable controller using Artisan:
php artisan make:controller Actions/MyAction --invokable
This will create a new invokable controller in the App/Http/Controllers/Actions directory. You can then remove the $request parameter from the __invoke method in the controller class:
namespace App\Http\Controllers\Actions;
class MyAction
{
public function __invoke()
{
// Your business logic here
}
}
You can then use this controller in your routes like this:
Route::get('/my-action', 'Actions\MyAction');
Note that if you need to pass parameters to your controller, you can do so by adding them to the __invoke method:
namespace App\Http\Controllers\Actions;
class MyAction
{
public function __invoke($param1, $param2)
{
// Your business logic here
}
}
And then passing them in your route:
Route::get('/my-action/{param1}/{param2}', 'Actions\MyAction');