You need to put check if you are getting any record then try to access name
.
$categoryName = $categories->where('slug', request()->category)->first();
if ($categoryName) {
$categoryName = $categoryName->name;
}
Basically due to chaining when you get null
in this query $categories->where('slug', request()->category)->first()
and you try to access name
property on null
you get this error.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…