调用未定义的方法Illuminate\Routing\Route :: get()

sho*_*cus 11 php phpstorm laravel laravel-routing laravel-5

我刚刚安装了Laravel 5.1,访问了我的应用程序的主页,我收到以下错误:

哎呀,看起来像出事了.

1/1

routes.php第16行中的FatalErrorException:

调用未定义的方法Illuminate\Routing\Route :: get()

在routes.php第16行

这是我的routes.php文件:

<?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');
});
Run Code Online (Sandbox Code Playgroud)

luk*_*ter 37

导入错误:

use Illuminate\Routing\Route;
Run Code Online (Sandbox Code Playgroud)

您实际上不必导入任何类,因为Laravel注册了一个全局别名Route.

如果要导入正确的类,那将是:

use Illuminate\Support\Facades\Route;
Run Code Online (Sandbox Code Playgroud)

  • 嗯.也许你的IDE做到了这一点.正如您在[Github](https://github.com/laravel/laravel/blob/master/app/Http/routes.php)上看到的那样,原始文件不包含此行. (2认同)

小智 5

评论这个:

// use Symfony\Component\Routing\Route; 
Run Code Online (Sandbox Code Playgroud)

用这个:

use Illuminate\Support\Facades\Route; 
Run Code Online (Sandbox Code Playgroud)