【问题标题】:How to pass one variable in every route by default?默认情况下如何在每条路由中传递一个变量?
【发布时间】:2018-06-27 04:38:55
【问题描述】:

我正在使用通配符子域。我已经定义了路由及其名称

Route::group(['domain'=>'{subdomain}.'.config('app.url')], function(){
    Route::resource('dashboard', 'Dashboard', ['as'=>'school']);
});

使用路由名称redirect(route('school.dashboard.index')) 重定向它时,它会显示Missing required parameters for...,如果我传递变量相同的路由名称,如redirect(route('school.dashboard.index', 'subdomainname')),它会完美运行。在这里,我必须使用路由名称在每个重定向中传递subdomain。我想要做的是,我想在每个路由名称中默认传递该变量。我该怎么做?

【问题讨论】:

  • 在配置文件中为子域设置另一个变量,例如config('app.url')

标签: php laravel routes subdomain


【解决方案1】:

DashboardController的方法中,你需要做这样的事情:

public function index($subdomain)

不仅仅是:

public function index()

https://laravel.com/docs/5.5/routing#route-group-sub-domain-routing

当您使用 route() 之类的帮助程序创建链接时,也要传递子域:

redirect(route('school.dashboard.index', ['subdomain' => $subdomain]))

【讨论】:

    猜你喜欢
    • 2013-10-09
    • 2023-02-06
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多