Neethu Ah's avatar

Laraval component Error

When i created a component "footer" and i pass a variable in it . but "Undefined variable $contactdata" error occurred.

app.blade code:

footer.blade:

Email Us

{{$contactdata->contactemail}}

footer componet: class footer extends Component {

public $contactdata;

/**
 * Create a new component instance.
 *
 * @return void
 */
public function __construct($contactdata)
{
     $this->contactdata = $contactdata;
}

/**
 * Get the view / contents that represent the component.
 *
 * @return \Illuminate\Contracts\View\View|\Closure|string
 */
public function render()
{
    return view('components.footer');
}

}

how to solve this..

0 likes
2 replies
vincent15000's avatar

$this refers to the component itself and $this->contactdata to the contactdata property inside the component. If you don't declare the variable as a property of the component, you won't be able to access to it.

You just have to declare the public variable inside the component class.

public $contactdata;

public function __construct($contactdata)
{
     $this->contactdata = $contactdata;
}

public function render()
{
    return view('components.footer');
}
Snapey's avatar

please format your code blocks so that we can better understand your question

Please or to participate in this conversation.