Answer the question
In order to leave comments, you need to log in
Why is my variable not found?
I'm trying to pass products from the database from the controller to the view.
controller:
public function index()
{
$allProducts = Product::all();
return view('index', compact('allProducts'));
}
@foreach( $allProducts as $product )
<img src="img/product.png" alt="..." class="image-responsive">
<div class="caption">
<h3>{{ $product->title }}</h3>
<p>{{ $product->description }}</p>
</div>
@endforeach
Route::get('index', function() {
return view('index');
});
Answer the question
In order to leave comments, you need to log in
You are in the route making the output of the view and not the direction to the controller action
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question