Custom controller for the frontend


November 19, 2020 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

Select One:

November 19, 2020 05:35 PM

Best Answer

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.


// Deprecated
Route::get('path', 'ExampleController@index');

For 8+ you have to pass it in via the fully qualified name.

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.

Select One:

November 23, 2020 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!

Select One:

Markdown Basics

DevDojo uses Markdown syntax for writing posts, commments, and other content throughout the site. Below you will find some commonly used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet

Bold & Italic

Italics *asterisks*

Bold **double asterisks**


Inline Code `backtick`

Code Block

Three back ticks and then enter your code blocks here.


# This is Heading 1
## This is Heading 2
### This is Heading 3
#### This is Heading 4
##### This is Heading 5

Here is an example of how each heading will looks

Heading 1

Heading 2

Heading 3

Heading 4
Heading 5


> type a greater than sign and start typing your quote.


You can add links by typing the alt text inside of [] and the link inside of (), like so:



You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the link inside of (), like so:

![alt text for image](

Embedding Codepens

You can also embed a codepen pen by writing the following:

{% codepen %}

You may also choose the default tabs you wish to show your pen by writing the default-tab like so: (default is result)

{% codepen default-tab=result,html %}

Embedding YouTube Videos

You can also embed a YouTube video by writing the following:

{% youtube VIDEO_ID_HERE %}

Embedding Katacoda Terminal

You can also embed a Katacoda Terminal by writing the following:

{% katacoda %}

You may also choose if the terminal should float at the bottom of the page or be embeded in the post itself by writing float like so:

{% katacoda float %}

Embedding Asciinema

You can also embed an Asciinema video by writing the following:

{% asciinema YOUR_VIDEO_ID %}

You may also choose if the video should be added as an alternate rel tag, so it could later on be played with the `asciinema play https://devdojo/post-name` command, with the rel argument like so:

{% asciinema YOUR_VIDEO_ID rel %}

That's about it. It's time to start crafting your story.

Please login, or signup to write a response.