You wrong in this code
$products = Product::with('category') ->where('products.is_active', '=', 't') ->where('categories.slug', '=', $slug) ->get();
This code only list products with category's id.
Error
Unknown column 'categories.slug'
It's mean haven't column 'categories.slug' in product's table.
I think you don't need check slug because all products has been check by categories.id
Thanks, but I want to find all products from category slug field. What is the correct syntax?
You can use this code
$slug = 'example';
$products = Product::whereHas('category',function($query) use ($slug){
$query->where('slug',$slug)
})->where('is_active','t')->get();
Thank you, that is exactly what I wanted. So I have to use a closure to find records based on a joined table?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community