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 )
)
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1QS9BVC
via IFTTT
Aucun commentaire:
Enregistrer un commentaire