Reputation: 11
This is my welcome.blade.php
@extends('layouts.app')
@section('content')
<x-frontpage></x-frontpage>
@endsection
This is my frontpage.blade.php
<h1 class="text-center">{{ $product->name }}</h1>
This is my error
$product is not passed to welcome.blade.php
Upvotes: 1
Views: 13288
Reputation: 31
You should add a props to your x-frontpage
blade component, otherwise it wouldn't be able to receive it.
Here's an example:
<!-- frontpage.blade.php -->
@props(['product'])
<h1 class="text-center">{{ $product->name }}</h1>
<!-- welcome.blade.php -->
@extends('layouts.app')
@section('content')
<x-frontpage :product="$product"></x-frontpage>
@endsection
Also make sure your welcome.blade.php
has the $product
variable.
Here are more resources:
https://laravel.com/docs/7.x/blade
https://laravel-livewire.com/docs/rendering-components#render-method
Upvotes: 3