Created
November 14, 2020 08:37
-
-
Save imam932/1dcf58511cdf90bbf33f8232cbe705a5 to your computer and use it in GitHub Desktop.
Get data multiple category id with whereIn
This file contains 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
<?php | |
public function index($slug) | |
{ | |
$parent = Category::where('slug', $slug)->first(); | |
$child = Category::where('parent_id',$parent->id)->get(); | |
$category_id = $parent->id; | |
$child_array_id = []; | |
foreach ($child as $key => $value) { | |
$child_array_id[$key] = $value->id; | |
} | |
$count = count($child_array_id)+1; | |
$mix_cat_id = $child_array_id[$count] = $category_id; | |
$reviews = Review::whereIn('product_id', function($query) use ($child_array_id){ | |
$query->select('id') | |
->from(with(new Product)->getTable()) | |
->whereIn('category_id', $child_array_id); | |
}) | |
->orderBy('created_at', 'desc') | |
->paginate(5); | |
return view('app.categories.index', compact('parent', 'child', 'reviews')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment