invalid argument supplied for foreach() laravel

Posted by w3diy - 5 months ago

invalid argument supplied for foreach() laravel

@foreach ($products as $product)
    <li>{{ link_to("/products/{$product->productname}", $product->productname) }}</li>
@endforeach

Get data

public function products() {
    $product = product::all();
    return View::make('products.index', ['products' => '$products']);
}

replace

$product = product::all();

to:

$products = product::all();

And remove the single quotes around $products:

return View::make('products.index', ['products' => $products]);