Character double colon does not exist in Laravel 5.3

Posted on

It is actually a typo which is normally made when a developer create a mistake in coding the source code application which in the context of this article is a web application based on Laravel 5.3 framework.

The error is shown below in the image :

Character double colon does not exist in Laravel 5.3
Character double colon does not exist in Laravel 5.3

And it is also generated in the laravel.log usually located in storage/logs folder :

[2017-02-12 15:50:17] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Parse error: syntax error, unexpected ':' in /var/www/html/laravel-project/app/Http/Controllers/ServerController.php:21
Stack trace:
#0 /var/www/html/infrastructure/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/html/i...')
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('App\\Http\\Contro...')
#2 [internal function]: spl_autoload_call('App\\Http\\Contro...')

Apparently there is a file named ‘ServerController.php’ located in a folder ‘app\Http\Controller’ and it is definitely become the source of the problem. It is pointed out that there is an error as shown below :

Parse error: syntax error, unexpected ':'

There is an error which is a syntax error in file named ‘ServerController.php’ located in ‘app\Http\Controller’ specifically in line 21. After checking the content of the file, below is the snippet code of the line which is indicated to be the source of the problem :

public function index(Request $request)
                $servers = Server:orderBy('id','DESC')->paginate(5);
                return view('server.index',compact('servers'))
                        ->with('i', ($request->input('page',1) - 1) * 5);

It is a default index method which is actually instructed to render every Server object in a paging consisting of 5 object of Server in every page.

As shown in the above snippet code, there is a line which is indicated to have a syntax error :

$servers = Server:orderBy('id','DESC')->paginate(5);

The above content can be repaired by changing the above line into the following content :

$servers = Server::orderBy('id','DESC')->paginate(5);

So, the indicated line which is triggering a syntax error is claimed as unexpected ‘:’ where on the contrary, it is an error because it is lack of another double colon. So, by adding the double colon from ‘:’ to ‘::’, the syntax error is easily can be handled.

It is actually the correct or the right way in order to call a function or a method available named ‘orderBy’ from a class named ‘Server’. Don’t forget the important thing which is normally even an expert developer can create a mistake by typing a line of code such as described above. Be sure to check and recheck again every line of source code.

One thought on “Character double colon does not exist in Laravel 5.3

Leave a Reply