-2

I'm getting this error when I try to read the data inside a view that returned by controller. I tried to change it many times but I still get same result

This is the controller index function where I launch the query and view

syntax error, unexpected ')', expecting '[' (View: C:\project\laravel\project1\app\resources\views\products.blade.php)

public function index()
{
    $data = DB::table('product')->get();
    return view('products',["products"=>$data]);
}

and this is the view part where I try to parse it:

<ul>
@foreach (products as product )
    <li>{{ product->name }}</li>
@endforeach
</ul>

if you have any idea or suggestion that s will be nice , thanks.

Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63
azdeviz
  • 597
  • 2
  • 9
  • 20

1 Answers1

2

The variables on PHP start with a $ sign. The $products and $product are variables so try to fix your code like this:

<ul>
@foreach ($products as $product)
    <li>{{ $product->name }}</li>
@endforeach
</ul>

Please check the Laravel templating docs

biesior
  • 55,576
  • 10
  • 125
  • 182
Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63