Laravel Error Message : Class name does not exist

Posted on

An article discuss on examining or trying to find out with the error message triggered in a Laravel based web application framework which is “Class name does not exist”. The error can be found for an example in the image shown below :

The error above generated when an execution of a certain page which has already defined in the route file of Laravel based web application project is carried out. The error which is specifically printed on the page is “Class name does not exist”.

It specifically point out a blade file template located in /resources/views which is a general location for folder intended to save blade file template. The blade file template which is becoming the culprit based on the above error message generated is ‘index.blade.php’. After checking through the snippet code, it is obvious that several line of it has become the main source or the triggered error. Below is the line of code :

@foreach($list_db as $key => $db)
{{ $app->name }}
{{ $app->version }}

In the above snippet code, there is an iteration or a loop using foreach to display information about list of available databases. Apparently, as we seen it in an instance, there is nothing wrong with the above snippet code. But on the other hand, the declaration of printing a value of name and also version of an object class named app is the cause of the error triggered as shown below :

{{ $app->name }}
{{ $app->version }}

The error triggered because there is no class named app has been declared before. The one which is should be written to correct the error triggered is by changing the class name as shown below :

{{ $db->name }}
{{ $db->version }}

It is obvious since in the foreach looping declaration, the variable involved as a class object is $db as shown in the foreach declaration :

@foreach($list_db as $key => $db)

So, the error related to the definition of the class name which is not exist early in the declaration in the foreach loop. But another circumstances or conditions which can triggered the error involving an object class can actually happened.

One thought on “Laravel Error Message : Class name does not exist

Leave a Reply