0
votes

I am getting the following error.

ErrorException Undefined variable $brands (View: C:\xampp\htdocs\wearwearemv\resources\views\backend\brand\brand_view.blade.php) http://127.0.0.1:8000/brand/view

I could not figure out what is wrong here. Any help?

Here is my route

Route::get('/brand/view', [BrandController::class, 'BrandView'])->name('all.brands');

Controller function

public function BrandView()
{
    $brands = Brand::latest()->get();

    return view('backend.brand.brand_view', compact($brands));
}

And my forloop

<tbody>
   @foreach($brands as $item)
   <tr>
     <td>{{ $item->brand_name }}</td>
     <td><img src="{{ asset($item->brand_image) }}" style="width: 70px; height: 40px;"></td>
     <td>
       <a href="" class="btn btn-info">Edit</a>
       <a href="" class="btn btn-danger">Delete</a>
     </td>
    </tr>
   @endforeach
</tbody>
1

1 Answers

1
votes

The compact function expects strings with variable names:

return view('backend.brand.brand_view', compact('brands'));