I deleted a category which is an f-key of the items table. Now the view has an error saying ‘Attempt to read property "category_name" on null’. How do I render a null foreign key?
I tried if-else:
@if({{$item->category->category_name}} === 'null')
<h2>no category</h2>
@else
{{ $item->category->category_name}}
@endif
2
Answers
Try this:
Or simply
In PHP8 or Larvel 8
simple use this one