0

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 Answer 1

1

The compact function expects strings with variable names:

return view('backend.brand.brand_view', compact('brands'));
Sign up to request clarification or add additional context in comments.

2 Comments

(facepalm) Thank you very much.
A mistake everyone makes sometimes :-D, You're welcome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.