我有通过此路由website.lrv/products/{category-url}调用的控制器website.lrv/products/{category-url}
public function categoryProducts($uri, Request $request) { /** some code **/ }我有几个负责订购产品的链接,我将它们直接添加到刀片模板中,如下所示:
route('client.category.products', [ 'url' => Route::current()->url, 'order' => 'article', 'by' => 'desc' ])
route('client.category.products', [ 'url' => Route::current()->url, 'order' => 'article', 'by' => 'asc' ])
订购的请求链接是: website.com/products/chargers?order=name&by=asc
现在我想添加产品过滤器。 我有很多过滤器,每个过滤器可以包含很多值。 问题是,我不知道如何让路线得到这样的: website.com/products/chargers?width=10,20,30&height=90,120,150或类似的东西。
我需要得到这样的请求数组:
$request = [ .... filters => [ width => ['10','20','30'], height => ['90','120','150'], ], .... ];`如果你需要一些额外的信息,我会编辑我的问题。
I have controller which called by this route website.lrv/products/{category-url}
public function categoryProducts($uri, Request $request) { /** some code **/ }I have a few links that are responsible for ordering products, i added them directly to blade template, like this:
route('client.category.products', [ 'url' => Route::current()->url, 'order' => 'article', 'by' => 'desc' ])
route('client.category.products', [ 'url' => Route::current()->url, 'order' => 'article', 'by' => 'asc' ])
And the request link with ordering is: website.com/products/chargers?order=name&by=asc
Now i want to add products filters. I have many filters, each filter can contain many values. The problem is that i don't know how to make route to get some like that: website.com/products/chargers?width=10,20,30&height=90,120,150 or something like that.
I need to get request array like that:
$request = [ .... filters => [ width => ['10','20','30'], height => ['90','120','150'], ], .... ];`If you need some additional info, i will edit my question.
最满意答案
您可以使用categoryProducts函数中的$request->query()来访问您要查找的数组。
编辑:另外值得注意的是,您可以使用Laravel帮助函数request()从刀片模板中访问它们,所以{{ request()->query('width') }}将返回xx ,其中website.lrv/products/category?width=xx 。
编辑2:请注意,如果您的查询字符串包含逗号(按您的示例width=10,20,30 ,query()将仅返回一个逗号分隔的字符串,所以您需要explode(',',$request->query('width'))以获得宽度数组
You can access the array you are looking for by using $request->query() within the categoryProducts function.
Edit: Also worth noting you can access them from within your blade template using the Laravel helper function request(), so {{ request()->query('width') }} would return xx where website.lrv/products/category?width=xx.
Edit 2: Note that if your query string includes commas per your example width=10,20,30 the query() will just return a comma separated string, so you would need to explode(',',$request->query('width')) in order to get the array of widths
更多推荐
发布评论