I am super stunned why this works for the first, but not for the else
part. I have the following function:
public function category($slug) {
if(!isset($slug[4])) {
$category_id = ProductCategory::where('slug', $slug[3])->first()->pluck('id');
} else {
$parent_id = ProductCategory::where('slug', $slug[3])->first()->pluck('id');
$category_id = ProductCategory::where('slug', $slug[4])->where('parent_id', $parent_id)->first()->pluck('id');
}
return $category_id;
}
$slug
is an array like this:
Array ( [0] => [1] => shop [2] => category [3] => women )
or
Array ( [0] => [1] => shop [2] => category [3] => women [4] => skirts )
When $slug[4]
is not available it returns the $category_id
fine, but when $slug[4]
is available, the exact same query ProductCategory::where('slug', $slug[3])->first()->pluck('id')
gives null, while $slug[3]
is in both cases the same...
A getQueryLog()
gives me this:
Array (
[query] => select * from `product_categories` where `slug` = ? limit 1
[bindings] => Array ( [0] => women )
)
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire