21

I have just installed Laravel 5.1, visited the home page of my app and i get the following error:

Whoops, looks like something went wrong.

1/1

FatalErrorException in routes.php line 16:

Call to undefined method Illuminate\Routing\Route::get()

in routes.php line 16

This is my routes.php file:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/



Route::get('/', function () {
    return view('welcome');
});
Community
  • 1
  • 1
showFocus
  • 701
  • 2
  • 8
  • 21

3 Answers3

62

This import is wrong:

use Illuminate\Routing\Route;

You actually don't have to import any class as Laravel registers a global alias Route.

If you want to import the right class, that would be:

use Illuminate\Support\Facades\Route;
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
  • Thanks for the answer, it worked. However, little confused as I did not put that import in. As mentioned this is a fresh install of Laravel. – showFocus Aug 29 '15 at 11:48
  • 2
    Hmm. Maybe your IDE did this. As you can see on [Github](https://github.com/laravel/laravel/blob/master/app/Http/routes.php) the original file doesn't contain this line. – lukasgeiter Aug 29 '15 at 11:51
  • 1
    Yes, PHPStorm seems the likely culprit. I had it automatically detect PSR-0 namespace roots when I created the project. – showFocus Aug 29 '15 at 11:53
  • Perhaps you should use command line composer dump-autoload after the laravel installation. – MaXi32 Aug 29 '15 at 14:02
  • 1
    @MaXi32 Composer has absolutely nothing to do with this problem. – lukasgeiter Aug 29 '15 at 14:03
  • @lukasgeiter I don't have this problem using laravel 5.1 with PHPStorm 8. BTW Composer fixed most of the namespace import problem in laravel :). It works most of the time for me. My opinion :) – MaXi32 Aug 29 '15 at 14:16
  • @MaXi32 Me neither. I suppose that PHPStorm went over all files and tried to resolve imports. And trust me, `composer dump-autoload` doesn't solve a wrong import. – lukasgeiter Aug 29 '15 at 14:18
  • @lukasgeiter And yet we still cannot answer why, PHPStorm tried to resolved the imports problem :) – MaXi32 Aug 29 '15 at 14:23
  • @lukasgeiter PHPStorm will try to resolve the wrong imports when you did not optimize your class loader by running composer dump-autoload. Class not found exception is common in laravel. So doing composer dump-autoload 'might' solve this problem earlier before PHPStorm messed up the namespace import problem. Reference: http://developed.be/2014/08/29/composer-dump-autoload-laravel/ – MaXi32 Aug 29 '15 at 14:35
  • Installed a Laravel Snippets extension on VSCode and it imported that line automatically at some point. Just removed the line and it's working fine. Although, a bit disappointed by the extension now. – sinaza Dec 10 '19 at 19:51
5

comment this:

// use Symfony\Component\Routing\Route; 

use this:

use Illuminate\Support\Facades\Route; 
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Anis Zaman
  • 51
  • 1
  • 1
0

Laravel VERSION = '5.2.30' using zendserver enterprise

On C:\Program Files (x86)\Zend\ZendServer\data\plugins\laravel\zray\ZRay.php from zend server, change line 193

From

if (get_class($route) != 'Illuminate\Routing\Route') {

To

if (get_class($route) != 'Illuminate\Support\Facades\Route') {   
Brane
  • 3,257
  • 2
  • 42
  • 53