November 19, 05:24 PM
I want to create a controller for the frontend views. The tutorial about that uses the web.php insteand, but I don'r like to put a lot of code on this file and I want to create a controller instead. I created one and extended the BaseController but I get always an error because laravel can't find my controller class. How can I do that? thanks
November 19, 05:35 PM
Depends on the version of Laravel. Since Laravel 8+ the namespace lookup was removed. The old style of looking for a controller via string isn't working anymore out-of-the-box.
//web.php // Deprecated Route::get('path', 'ExampleController@index');
For 8+ you have to pass it in via the fully qualified name.
//web.php use App\Http\Controllers\ExampleController; Route::get('path', [ExampleController::class, 'index']);
For more information check our the Laravel documentation on controllers.
I also just published a new article on controllers called Laravel Quickie: Basic Controllers that might be helpful.
November 23, 12:10 PM
Ops I didn't realize that I installed the 8.12. And I need as you said to declare first the controller. Thanks!