Hi, how are you?! I am making an Ecommerce and my homepage "Welcome" should have a list of products, but I am not able to because it is giving undefined variable $products in foreach
what can I do?
its my foreach in welcome.blade.php
@foreach($products as $product)
<div class="card">
<div class="imgBox">
<img src="" alt="" class="product">
</div>
<div class="contentBox">
<h3>{{$product['name']}}</h3>
<h2 class="price">R$ {{$product['price']}}</h2>
<a href="{{ url('#') }}" class="buy">Comprar</a>
</div>
</div>
@endforeach
its my route.php
Route::get('/', [WelcomeController::class, 'index'])->name('welcome');
and its my Controller(WelcomeController.php)
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
class WelcomeController extends Controller
{
public function index (Product $product){
return view('welcome')->with(['products' => Product::all(), 'categories' => Category::all()]);
}
}