本文介绍了如何将静态变量传递给Laravel路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将Symfony路由重写为Laravel路由.问题是某些Symfony路由采用defaults
并进入同一控制器.我可以在Laravel路由中添加一些参数来实现相同的功能吗?
I try to rewrite Symfony routes to Laravel routes. The problem is that some Symfony routes take defaults
and go the same controller. Can I add some arguments to the Laravel routes to accomplish the same?
例如Symfony yaml
path: /account/
defaults:
_controller: "legacy.controller.fallback:Somefunt"
pag_act: "secret"
m_act: "home"
path: /account2/
defaults:
_controller: "legacy.controller.fallback:Somefunt"
pag_act: "public"
m_act: "home"
例如laravel
Route::any('/account', 'SomeSymfonyController@Somefunt');
您会看到:这2条Symfony路由的默认设置不同(pag_act),我也可以在Laravel中传递它吗?
As you can see: the defaults for these 2 Symfony routes are different (pag_act), can I pass this in Laravel too?
推荐答案
Route::any('/account', 'SomeSymfonyController@Somefunt')
->defaults('pag_act', 'secret');
Route::any('/account2', 'SomeSymfonyController@Somefunt')
->defaults('pag_act', 'public');
以及您的SomeSymfonyController Somefunt
方法中
and in your SomeSymfonyController Somefunt
method
public function Somefunt(Request $request)
{
dd($request->route('pag_act')); // Returns 'secret' or 'public' based on route
}
这篇关于如何将静态变量传递给Laravel路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!