Recently i have learning laravel and i following a project on youtube. I was make sure that i'm following correctly what he doing and why my wire:click on delete button are not working as he does
livewire index.php
public function deleteCategory($category_id) {
$this->$category_id = $category_id;
}
public function destroyCategory()
{
$category = Category::find($this->category_id);
$path = 'uploads/category/'.$category->image;
if(File::exists($path)) {
File::delete($path);
}
$category->delete();
session()->flash('message','Category Deleted');
$this->dispatchBrowserEvent('close-modal');
}
livewire index.blade.php
Category Delete
Are you sure?
Close
Yes
</div>
</div>
@if (session('message'))
<div class="alert alert-success">{{ (session('message')) }}</div>
@endif
<div class="card">
<div class="card-header">
<h4>Category
<a href="{{ url('admin/category/create') }}" class="btn btn-primary btn-sm float-end">Add category</a>
</h4>
</div>
<div class="card-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
<th>Image</th>
<th>Action</th>
</tr>
<tbody>
@foreach ($categories as $category)
<tr>
<td>{{ $category->id }}</td>
<td>{{ $category->name }}</td>
<td>{{ $category->status == '1' ? 'Hidden':'Visible'}}</td>
<td>{{ $category->image }}</td>
<td>
<a href="{{ url('admin/category/'.$category->id.'/edit') }}" class="btn btn-success">Edit</a>
<a href="#" wire:click="deleteCategory({{$category->id}})" data-bs-toggle="modal" data-bs-target="#deleteModal" class="btn btn-danger">Delete</a>
</td>
<td>{{ $category->action }}</td>
</tr>
@endforeach
{{ $categories->links('pagination::bootstrap-5') }}
</tbody>
</thead>
</table>
<div>
{{-- {{ $categories->links() }} --}}
</div>
</div>
</div>
</div>
@push('script')
window.addEventListener('close-modal', event => {
$('#deleteModal').modal('hide');
});
@endpush
i try to find error but it didn't display anything, can u guys help me find it, thanks so much :(((