Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

having trouble in displaying the data passed to components in laravel

I’m trying to learn laravel and now I’m in the part of passing the Data to components but everytime I run this code nothing Displays

in my welcome.blade.php:

<x-header name =  "Joanna"/>  

in my Header.php:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php

namespace App\View\Components;

use Illuminate\View\Component;

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

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

in my header.blade.php:

<div>
    <h1>Hi {{ $name }}</h1>
</div>

I hope you can help me I’m stuck in this for hours…thank you

>Solution :

Your blade component doesn’t seem right. Try removing the spaces on the HTML attribute like:

<x-header name="Joanna" />  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading