我希望能够使用包中的路由覆盖app/Http/routes.php中定义的路由.
例如,在app/Http/routes.php中,我可能会这样:
Route::get('/search/{type?}',['as' => 'search','uses' => 'SearchController@search']);
Run Code Online (Sandbox Code Playgroud)
我希望能够在/vendor/author/package/src/Http/routes.php中定义它:
Route::get('/search/properties', ['as' => 'properties','uses' => 'PropertyController@search']);
Run Code Online (Sandbox Code Playgroud)
首先加载app/Http/routes.php文件,以便使用它们中的路由,而不是包.
在Laravel 4中,我会使用App :: before或App :: after来做到这一点,给予他们优先权.
像包裹路线一样:
App::before(function() {
Route::get('/search/properties', ['as' => 'properties','uses' => 'PropertyController@search']);
});
Run Code Online (Sandbox Code Playgroud)
我不知道如何在Laravel 5中实现这一点.我发现这个https://mattstauffer.co/blog/laravel-5.0-middleware-filter-style,但不知道怎么用它来做我想要的.
编辑:Laravel 4执行此操作的方法将允许为每个路由设置此优先级,因此我不只是在应用程序之前加载所有包路由.
我正在尝试运行此查询:
$products = $this->product_model->where(function($query) use ($key) {
$query->whereHas('categories', function ($category) use ($key) {
$category->where('key', $key);
});
$query->orWhereHas('parent.categories', function ($category) use ($key) {
return $category->where('key', $key);
});
});
Run Code Online (Sandbox Code Playgroud)
父关系是另一个产品,所以它来自同一个表。我遇到的问题在于它产生的查询:
SELECT *
FROM `products`
WHERE (
(SELECT count(*)
FROM `categories`
INNER JOIN `category_product` ON `categories`.`id` = `category_product`.`category_id`
WHERE `category_product`.`product_id` = `products`.`id`
AND `key` = 'mens'
) >= 1
OR
(SELECT count(*)
FROM `products` AS `self_30ec5d4782a83841add518f618b9f59e`
WHERE `self_30ec5d4782a83841add518f618b9f59e`.`id` = `products`.`parent_product_id`
AND
(SELECT count(*)
FROM `categories`
INNER JOIN `category_product` ON `categories`.`id` = `category_product`.`category_id`
WHERE …Run Code Online (Sandbox Code Playgroud)