调用未定义的方法Route :: name() [英] Call to undefined method Route::name()

查看:72
本文介绍了调用未定义的方法Route :: name()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的路线设置名称

im trying to set a name for my route

Route::get('test/show/{id}' , 'TestController@show');

根据文档

不是在路由数组定义中指定路由名称, 您可以将name方法链接到路由定义的末尾:

Instead of specifying the route name in the route array definition, you may chain the name method onto the end of the route definition:

Route::get('user/profile','UserController@showProfile')->name('profile');

所以我写了

Route::get('test/show/{id}' , 'TestController@show')->name('testShow');

但是我得到

FatalErrorException in routes.php line 28:
Call to undefined method Illuminate\Routing\Route::name()
in routes.php line 28
at FatalErrorException->__construct() in compiled.php line 1743
at HandleExceptions->fatalExceptionFromError() in compiled.php line 1738
at HandleExceptions->handleShutdown() in compiled.php line 0
in compiled.php line 17158
at RouteServiceProvider->App\Providers\{closure}() in compiled.php line 6819
at call_user_func() in compiled.php line 6819
at Router->group() in compiled.php line 17159
at RouteServiceProvider->map() in compiled.php line 925
at call_user_func_array() in compiled.php line 925
at Container->call() in compiled.php line 4858
at RouteServiceProvider->loadRoutes() in compiled.php line 4840
at RouteServiceProvider->boot() in compiled.php line 17153
at RouteServiceProvider->boot() in compiled.php line 925
at call_user_func_array() in compiled.php line 925
at Container->call() in compiled.php line 1518
at Application->bootProvider() in compiled.php line 1510
at Application->Illuminate\Foundation\{closure}() in compiled.php line 1511
at array_walk() in compiled.php line 1511
at Application->boot() in compiled.php line 1785
at BootProviders->bootstrap() in compiled.php line 1311
at Application->bootstrapWith() in compiled.php line 1928
at Kernel->bootstrap() in compiled.php line 1890
at Kernel->sendRequestThroughRouter() in compiled.php line 1880
at Kernel->handle() in index.php line 53
in index.php line 21
at {main}() in index.php line 0

推荐答案

此导入错误:

使用照亮\路由\路由;

use Illuminate\Routing\Route;

当Laravel注册一个全局别名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:

使用Illuminate \ Support \ Facades \ Route;

use Illuminate\Support\Facades\Route;

位于route.php文件顶部

on top of route.php file

这个问题 对我来说效果很好...您确定您至少有Laravel 5.1版本吗?此功能在5.0中不可用

this problem Works fine for me... Are you sure you have at least Laravel 5.1 version? This feature wasn't available in 5.0

如果不是: 您需要运行

If not : You need to run

composer update

在您的终端机中

以获得最新的Laravel 5.1.*版本.

in your terminal to get the latest Laravel 5.1.* version.

这篇关于调用未定义的方法Route :: name()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆