簡釋什麼維尼修斯·路易斯說。
Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => '[email protected]']);
// to get the actual linke
route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);
依賴,你可能做不到 - > ID或任何東西,你可能只是通過整個$類,$產品等依賴於你的控制器路由的設置方式。
編輯: 從您的評論,它喜歡像你想是這樣的:
class MenuController {
public function lisItem($category_name, $product_name) {
$category = Category::where('name', $category_name)->first(['id']);
$product = Product::where('category_id', $category->id)->where('name', $product_name')->first();
}
}
Route::get('/{category}/{item}', ['as' => 'named.route' , 'uses' => '[email protected]']);
// to get the actual linke
route('named.route', ['category' => $category->id, 'item' => $item->id]);
有可能是一個更好的方式做了查詢,但應該爲你工作。
對不起,我試圖把嗨,但它看起來並不想更新,因爲有人射我:D – JroS
你的目的是什麼? – trinvh
目的只是將「http:// localhost:8080/menu/homme/bijoux/pendentif」中的網址替換爲「http:// localhost:8080/homme/pendentif」,其中homme爲{category}, pendentif是{item] – JroS