2016-04-08 58 views
0

路线我在laravel5相当新的,我想下生成route.phpLaravel 5命名为参数

动态路由别名这是它:

Route::get('/menu/{category}/{product}/{item}', '[email protected]')->name('/{category}/{item}'); 

我已经尝试过用“作为”和“使用”,我仍然得到:

/menu/{category}/{product}/{item} 

与正确的价值观,而不是更换所有参数:

/{category}/{item} 
+0

对不起,我试图把嗨,但它看起来并不想更新,因为有人射我:D – JroS

+0

你的目的是什么? – trinvh

+0

目的只是将“http:// localhost:8080/menu/homme/bijoux/pendentif”中的网址替换为“http:// localhost:8080/homme/pendentif”,其中homme为{category}, pendentif是{item] – JroS

回答

2

试试:

Route::get('/menu/{category}/{product}/{item}', ['as' => 'a.name.to.your.route' , 'uses' => '[email protected]']); 
+0

尝试扩大你的答案,至于你做了什么来解决问题。 – Wowsk

+0

嗨路易斯感谢相同的结果看起来像没有使用 – JroS

0

简释什么维尼修斯·路易斯说。

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]); 

有可能是一个更好的方式做了查询,但应该为你工作。

+0

您好Kenyon thx您的答复,但你失去了我我虽然我的问题很简单,我只是想用另一个使用给定的参数替换显示的URL,如示例中所示。有没有可能? – JroS

+0

我不确定你想要完成什么?按照我给你的方式,你最终会得到一个像'/ menu/10/5/6'这样的URL,当查看时它将解析为'MenuController @ listItem'。你想尝试别名路线吗?或者你是否想让URL显示不同?你究竟想要什么网址? – Kenyon

+0

exaclty我只是想显示的url是不同的什么是用于路由采取你的例子我只想看/ 10/6 – JroS