I’m encountering an issue in my Laravel application when I try to access the URL https://example.com/sitemaps.xml. The error message I receive is ‘Attempt to read property "slug" on null’.
The error seems to be originating from the following line in my resources/views/default/sitemaps.blade.php
file:
{{ url('category', [$subcategory->category->slug, $subcategory->slug]) }}
Can anyone help me understand why this error is occurring and how I can resolve it?
2
Answers
try this
and make sure that $subcategory->category is not NULL
The above error occurs when accessing the slug property from a null category object. Here are two possible solutions:
For PHP v8 or above
For PHP v7 or above