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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀