In a laravel blade in third line of this code I want to check if parent_id exists in id column or not
please help me!
I’m using laravel 9
@if ($category->parent_id == 0)
no parent
@if ($category->parent_id)
no parent
@else
{{ $category->parent->name }}
@endif
I corrected it this way:
@elseif (empty($category->parent))
3
Answers
Balde:
you can use the
empty()
to check if empty.or
??
operatorYou can use the
is empty
in twig as below:You can try by using isset() function
Using exists() function for parent()
Not that exists function works just with single relations (belongsTo, hasOne)
If you want to save performance and not calling sql query