Created
January 18, 2019 14:29
-
-
Save me7media/ce7061433aae165e5de64644513c9eae to your computer and use it in GitHub Desktop.
Получение товаров категории и ее дочерних категорий с условиями
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$products = null; | |
Category::whereId($category_id)->with([ | |
'products' => function ($q) use (&$products, $search) { | |
$products = $q->where('active', true) | |
->search($search) //Scope | |
->get() | |
->unique(); | |
}, | |
'childrens.products' => function ($q) use (&$products, $search) { | |
$products = $q->where('active', true) | |
->search($search) //Scope | |
->get() | |
->unique(); } | |
])->get(); | |
//Scope | |
public function scopeSearch($query, $value) | |
{ | |
return $query->where('name', 'LIKE', '%' . $value . '%') | |
->orWhere('full_name', 'LIKE', '%' . $value . '%') | |
->orWhere('code', 'LIKE', '%' . $value . '%') | |
->orWhere('article', 'LIKE', '%' . $value . '%'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment