前提
現在Laravelで店舗一覧ページ(admin/shops/index.blade.php)をコントローラーのindexメソッド内でreturn view(admin.shop.index)で表示しております。
表示しています。
実現したいこと
この画面の一番右のボタンの商品管理ボタンをクリックすると、各レコードの商品管理ページ(admin/products/index)へ遷移させたいのですが、この店舗一覧ページのそれぞれのレコードからどうやったら商品IDなどの情報を取得するべきか悩んでいます。
該当のソースコード
ルート設定のadmin.php // ショップ関連 Route::get('shops/', [ShopController::class,'index'])->name('shops.index'); // 商品管理関連 Route::get('products/', [ProductController::class,'index'])->name('products.index');
**admin/shops/index.blade.php** //店舗一覧画面の繰り返し部分 @foreach($shops as $shop) <tr> <td><x-thumbnail :filename="$shop->filename" type="shops" /></td> <td class=" py-3"><a href="{{ route('admin.shops.show', $shop->id ) }}">{{ $shop->name }}</a></td> <td class=" py-3 whitespace-nowrap">{{ $shop->delegate }}</td> <td class=" py-3 whitespace-nowrap">{{ $shop->address }}</td> <td class=" py-3 whitespace-nowrap">{{ $shop->tel }}</td> <td class=" py-3 whitespace-nowrap">{{ $shop->email }}</td> <td class=" py-3 whitespace-nowrap"> <a href="{{ route('admin.shops.edit', $shop->id) }}" class=" text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg">更新する</a></td> <td class=" py-3 whitespace-nowrap"><a href="{{ route('admin.products.index') }}" class=" text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg">商品管理</a></td> </tr> @endforeach
コントローラーの場所
App\Http\Controllers\Admin\ShopController;
App\Http\Controllers\Admin\ProductController;
試したこと
商品管理ボタンのリンク先のパラメータで
<a href="{{route(admin.products.index,$shop->id)}}"としてもコントローラのindexでは使用できません。
商品管理ボタンを<form>タグで囲って、<a>タグではなく<button type="submit"〜>にして、<form>タグの中に<input type="hidden" value="{{ $shop->id }}">も試しました。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。