Variable data not transfered to livewire component

I have a livewire component in a blade file and want to transfer some data to it. If I do a cache clear in laravel, and reclick on the button the data gets transfered to the livewire component.
Here is the code.

image

However the data gets displayed in de blade model (parent to the livewire component.)

I thank you in advance for any help.

Hey, @ALAINF971

I didn’t understand your code example. However, if you want to share some data with a livewire component [parent or child] you need to pass it to the component directive.

For example:
Let’s say you want to share the user information with the livewire component because you want to do some logic in it.

In your blade:

@livewire('share-data', ['user' => $user])

In your component

public function mount($user)
{
  // do your logic
}

So, let’s say you want to share data between the parent component and their children. You need to pass the data also into the child component as you do it with the parent with the same logic above.

PS: If you got your question wrong, please explain it a little for better understanding.

Thanks for the reply.
I edited my question, removed a photo.
I did like you have shown, but the logic I had in the mount method does not seem to get used.

Hi, @ALAINF971

Still can’t get the idea of the question. What do you want to do exactly?

In my blade page I have $averageRating that I want to pass to the livewire component so as to use it I am not able to use its value, it is not passed through.
So for now I am using a blade component instead and it does What I need it to do.

See the example above, I explained to you how to do it with a livewire component.

If you want how to do it with blade component see the link below
https://laravel.com/docs/8.x/blade#components

You have in AssignedDriver class the public property $rating, and like is public is shared to the blade. So, if in that blade you include a nested component like @livewire(’…’) and that component in mount method is expecting data binded (like you refer) you need to pass the correct value and syntax. In your case you must do it:

@livewire('assigned-driver', ['averageRating' => $parent_component_public_property])

Now, I saw you make the things a little confuse because you assign this value to another property and after this last (public $rating) is include in render method with the before property name…I mean, make it simple. This is my way

...
public $rating;

public function mount($rating)
{
   $this->rating = $rating;
}

public function render()
{
    return view('livewire.assigned-driver'); //once $rating is public don't need be put in here
}

and in parent blade component

@livewire('assigned-driver', ['rating' => $parent_component_public_property])