【问题标题】:Laravel 5.5 Naming Route::resource for later useLaravel 5.5 命名 Route::resource 供以后使用
【发布时间】:2018-06-03 00:47:29
【问题描述】:

如何命名我的 Route::resource 以便稍后在 Laravel 5.5 中调用它?

这行得通 Route::get('newclientTAB', 'NewClientControllerTAB@index')->name('newclientTAB');

这不是 Route::resource('articles','ArticleController')->name('articles');

【问题讨论】:

    标签: laravel laravel-5 laravel-routing laravel-5.5 laravel-artisan


    【解决方案1】:

    如果你使用:

    Route::resource('articles','ArticleController')
    

    Laravel 会自动为你的路由设置名称。

    你可以运行:

    php artisan route:list
    

    看到他们。

    遗嘱有名字:

    • articles.index
    • articles.store
    • articles.create
    • articles.show
    • articles.update
    • articles.destroy
    • articles.edit

    但是,如果您想使用自定义名称前缀,您可以这样设置:

    Route::resource('articles','ArticleController', ['names' => 'xyz'])
    

    然后您的路线将有名称xyz.indexxyz.store 等等

    如果您想更进一步,您还可以设置个人名称,例如:

    Route::resource('articles','ArticleController', ['names' => ['create' => 'foo','update' => 'bar']])
    

    所以你可以只为一些路由设置名称,这样你就会得到foobararticles.indexarticles.show等等

    【讨论】:

    • 稍后,但这应该可以工作Route::resource('articles','ArticleController')->names('xyz'); 注意方法从name 更改为names!在 Laravel 5.6 中工作(未在早期版本中测试)
    猜你喜欢
    • 2018-11-06
    • 2019-06-14
    • 2014-06-23
    • 2013-10-06
    • 1970-01-01
    • 2018-04-21
    • 2016-02-18
    • 1970-01-01
    • 2014-06-23
    相关资源
    最近更新 更多