dqqs64238 2016-06-29 22:49
浏览 465
已采纳

调用未定义的方法Route :: name()

im trying to set a name for my route

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

accourding to documentation

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');

so i wrote

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

but i get

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
  • 写回答

3条回答 默认 最新

  • duanjizi9443 2016-06-29 22:57
    关注

    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;

    on top of route.php file

    EDIT: 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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64