October 02, 2021 Uncategorized 0 Comment

Laravel provides a single action controller called invokable controller which contains a invoke method to perform a single task. So for doing only single task we can use this invokable controller.  there’s __invoke() method.

In Laravel 5.6+, you can create a Controller with only one method __invoke():

You can also generate this kind of Controller, with this Artisan command:

php artisan make:controller ProfileController --invokable

Have a look at the above code that there is no method. That means it is an invokable controller. If there is no method in the controller then the controller will call a method called Invoke. Something like that

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
    public function __invoke()
        //some codes goes here