このルートの場合
Route::get('/locations/{location?}/actions/{action?}/screens/{screen?}','GameController@index')->name('locations.actions.screens.show');
GameController index メソッドでは、これらのパラメーターを次のように取得できます。
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());
}
特定のアクションに属し、特定の場所に属している特定の画面に属しているすべてのゲームを取得したいと考えてみましょう。あなたの URL は質問にあると思われます。その場合、URL は次のようになります。
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
}