这条路线
Route::get('/locations/{location?}/actions/{action?}/screens/{screen?}','GameController@index')->name('locations.actions.screens.show');
在 GameController 的索引方法中,您可以将这些参数获取为
public function index(Location $location, Action $action, Screen $screen) {
// here you can use those models
}
如果您使用的是路由模型绑定,
如果不使用
public function index($location, $action, $screen) {
// here you can use these variables
}
如果路由名称是locations.actions.screens.show,那么在视图中,它将是
<a href="{{ route('locations.actions.screens.show', ['location' => $location, 'action' => $action, 'screen' => $screen ]) }}">Test</a>
现在,如果你有一些查询参数
那么它就像 $http://example.com/?test="some test data"&another_test="another test"
你可以像这样访问这些参数
public function myfunction(Request $request) {
dd($request->all());
}
假设您要检索属于特定屏幕、属于特定操作且属于特定位置的所有游戏,您的网址在您的问题中似乎是什么,在这种情况下,网址将是
Route::group(['prefix' => 'game'], function (){
Route::get('locations/{location?}/actions/{action?}/screens/{screen?}','GameController@index')->name('game.index');
});
url 似乎是 game/locations/1/actions/1/screens/1 其中操作和屏幕参数可以是可选的
现在在你的控制器 index() 方法中
public function index(Location $location, Action $action=null, Screen $screen=null) {
//using the model instance you received, you can retrieve your games here
}