Hi all,
I’m new to Livewire, and am implementing a project for a client of mine. For some reason I can’t get wire:click to call a function in my component. I have done small tutorials from Livewire site from Caleb and those work fine, just not in my own project. Maybe someone can spot the stupid mistake I am making?
I’m using “livewire/livewire”: “^1.3”. Below is my Livewire component blade template:
@include('layouts.template')
@section('content')
<div class="flex justify-center mt-12">
<table class="table-fixed mb-8">
<thead>
<tr>
<th class="w-1/2 px-32 py-2 text-yellow-400">Name</th>
<th class="w-1/4 px-32 py-2 text-yellow-400">Compromises</th>
<th class="w-1/4 px-32 py-2 text-yellow-400">Download</th>
</tr>
</thead>
<tbody>
@foreach ($clients as $client)
@if ($loop-> index % 2 )
<tr class="bg-gray-600">
@else
<tr class="bg-gray-700">
@endif
<td class="border px-32 py-2 text-center">{{ $client['title'] }}</td>
<td class="border px-64 py-2 text-center">{{ $client['compromise_count'] }}</td>
<td class="border px-32 py-4">
<button
wire:click="downloadReport({{ $client['uuid'] }})"
class="bg-gray-300 text-black font-semibold px-4 py-2 w-32 hover:bg-yellow-400 hover:text-white">Download
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
So that calls a function called downloadReport(), and in Chrome developer console I can see that it is picking up the UUID of the customer fine and passing it through:
<button wire:click="downloadReport(7453a5d0-6a44-4510-a25c-34bec60738bc)" class="bg-gray-300 text-black font-semibold px-4 py-2 w-32 hover:bg-yellow-400 hover:text-white">Download</button>
This is my Livewire component function:
public function downloadReport($uuid)
{
// my code here, but this function never fires
}
And I have this route in web.php:
Route::livewire('/darkweb', 'lwdarkweb')->layout('layouts.template');
Interestingly the mount() function works perfectly fine! I just can’t get the downloadReport() function to fire. I’m just really stuck and can’t figure this out
Also in my layouts.template file I do have the <livewire:styles /> and <livewire:scripts /> added into head and body respectively. Here’s a small snip of my table with the Download buttons for some context:
Let me know what other info you may need to help me?
Thanks!
Hendrik