Search code examples
laravellaravel-livewire

laravel syntax error, enexpected ',' , expecting ';'


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.


Solution

  • 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');
    }