Invokable Controller for Laravel 8

namespace App\Http\Controllers;

class InvokableController extends Controller
{
    public function __invoke()
    {
        return 'This is an invokable controller';
    }
}
use App\Http\Controllers\InvokableController;

Route::get('/invokable', InvokableController::class);

Laravel 8 gets rid of the automatic namespace attached to routes, so going forward you will have to use the FQCN by default, it can always be added back in you if you wanna use the old routing style, just modify your RouteServiceProvider.

public function boot()
{
    $this->routes(function () {
        Route::middleware('web')
            ->namespace('App\Http\Controllers')
            ->group(base_path('routes/web.php'));

}

© 2020 DevDojo LLC. All rights reserved.