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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32285647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:53:20  来源:igfitidea点击:

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

phplaravellaravel-5phpstormlaravel-routing

提问by showFocus

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

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

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

哎呀,看起来出事了。

1/1

route.php 第 16 行中的 FatalErrorException:

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

在 routes.php 第 16 行

This is my routes.php file:

这是我的 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');
});

回答by lukasgeiter

This import is wrong:

这个导入是错误的:

use Illuminate\Routing\Route;

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

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

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

如果你想导入正确的类,那就是:

use Illuminate\Support\Facades\Route;

回答by Anis Zaman

comment this:

评论这个:

// use Symfony\Component\Routing\Route; 

use this:

用这个:

use Illuminate\Support\Facades\Route; 

回答by user6238341

Laravel VERSION = '5.2.30'using zendserver enterprise

LaravelVERSION = '5.2.30'使用zendserver enterprise

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

C:\Program Files (x86)\Zend\ZendServer\data\plugins\laravel\zray\ZRay.phpZend 服务器上,更改第 193 行

From

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

To

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