Accessing array offset on value of type null error in Laravel

141 Views Asked by At

The following is my code, and it's a public function. Thie error is in PHP 7.4; I am stuck for hours, and I've tried many solutions. When I try to access the value of $banner['img_name'], it shows me an error on a query. I have used this syntax before; it works fine in another controller.

$categories = Category::all();
$size = Category::count();

$uploaded_categories_code = NULL;

foreach ($categories as $category) {
    $banner = CategoryBanner::where('category_id', $category['id'])->first();

    $imageCover = asset("images/categories/covers/" . $category['img_name']);
    $imageBanner = asset("images/categories/banners/" . $banner['img_name']);
}
0

There are 0 best solutions below