Trid22's avatar

Livewire 3 dispatch problems

I am trying to get dispatch from 1 component to another. At the moment I getting this error "Attempt to read property "name" on null"

Here is the blade file that is dispatching

            @if(!empty($query))
              @if(!empty($contacts))
                @foreach($contacts as $contact)
                  <option><a wire:click="showphotos({{$contact->name}})" href="/create-photo/{{$contact->id}}">{{$contact->name}}</option>
                @endforeach 
             @else
               <div>No Result</div>
          @endif 
       @endif
 
$wire.dispatch('create-photo',{$contact->name});

Here is the listening component

class CreatePhoto extends Component { public $contact;

 #[On('create-photo')]
    public function showphotos($name){ 
    $this->name =$name; 
       
 }

public function render()
{
    return view('livewire.create-photo');           
 }

}

Here is the blade file

 <h4>{{$contact->name}}</h4>
0 likes
3 replies
Trid22's avatar

This is my first post, I am editing now. There is no component has that data

jaseofspades88's avatar

Plenty of Livewire videos on Laracasts to watch that will help you learn the basics

Please or to participate in this conversation.