-1

I tried to fix this but don't know how

enter image description here

public function render()
{
    return view('livewire.home')->extends('layouts.app')->section('content'),[
        'products' => Product::take(3)->get()
    ];

It said that the syntax is error,

unexpected ',', expecting ';'

I'm newbie to Laravel so I couldn't write the correct syntax. Please let me know.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
m4rsy4
  • 15
  • 3
  • 1
    You already closed all `)` so you can't add a second paramter to any method. Check your `)` – shaedrich Jun 17 '21 at 14:23
  • Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Qirel Jun 17 '21 at 15:17

1 Answers1

0

As you can see in the docs, to pass variables to the view, you need to set the second parameter in the method view() as the array of data.

public function render()
{
    return view('livewire.home', [
        'products' => Product::take(3)->get()
    ])->extends('layouts.app')->section('content');
}
N69S
  • 16,110
  • 3
  • 22
  • 36
  • thank you for your response, but after I open my localhost it says that the Class 'App\Product' not found – m4rsy4 Jun 22 '21 at 15:22
  • @m4rsy4 you need to set the namespace either at the top of your file with `use App\Models\Product;` (the namespace depends on where is your class and declared namespace in it) or in the code – N69S Jun 22 '21 at 16:37