0

I'm trying to create a simple table list view with laravel and livewire component. I can show the component but when I fire an event (change, wiremodel, click) the dataset is not updating, for example, I have an input text to filter my table, when I write on input the request is firing and component is getting it but component nor re-render with the new information

That's my full view

<header class="header py-6">

    <div class="flex justify-between">
        
        <h2 class="font-bold text-2xl text-blue-dark leading-tight">
            {{ __('messages.Seizures') }}
        </h2>
        
        <div class="flex items-end">
            <div class="cursor-pointer"> 
                <i class="fas fa-plus-circle text-blue-light text-3xl"></i>
            </div>
            <div class="pl-8 flex items-center">
                    <i class="fas fa-filter text-blue-light text-lg"></i>
                    <input type="text" name="search" id="search-seizure" class="border border-blue-light rounded-full h-8 ml-1 px-4 text-blue-light" wire:model="filter">
            </div>
            <div class="pl-8 cursor-pointer" wire:click.prevent="toggleTrash()">
                @if( $trash )
                    <i class="fas fa-trash text-blue-light text-xl"></i><i class="fas fa-toggle-on text-blue-light text-xl"></i>
                @else
                    <i class="fas fa-trash text-gray-400 text-xl"></i><i class="fas fa-toggle-off text-xl text-gray-400"></i>
                @endif
            </div>
        </div>
    </div>
</header>
    
    <div class="seizure-page">
        <table class="table">
        <thead>
            <tr>
                <th>@sortablelink('date', __('messages.Date'), [], ['class' => 'pr-2'])</th>
                <th>{{ __('messages.Duration') }}</th>
                <th>@sortablelink('location', __('messages.Location'), [], ['class' => 'pr-2'])</th>
                <th>{{ __('messages.Notes') }}</th>
                <th width="100px" class="text-right">{{ __('messages.Actions') }}</th>
            </tr>
        </thead>

        <tbody>
            @foreach($seizures as $seizure)
            <tr class="cursor-pointer">
                <td>{{ $seizure->date }}</td>
                <td class="w-64">{{ $seizure->duration }}</td>
                <td>{{ $seizure->location }}</td>
                <td class="truncate-cell">{{ $seizure->note }} </td>
                <td class="end">
                    <div class="flex justify-end">
                        <button wire:click="" class="btn btn-danger btn-sm px-1"><i class="fas fa-info"></i></button>
                        <button wire:click="edit({{ $seizure }})" class="btn btn-primary btn-sm px-1"><i class="fas fa-pen"></i></button>
                        <button wire:click="delete({{ $seizure }})" class="btn btn-danger btn-sm px-1"><i class="fas fa-trash text-warm-red"></i></button>
                    </div>
                </td>
            </tr>
            @endforeach
        </tbody>

    </table>
    <div class="flex justify-center pt-4">
        {{ $seizures->links('vendor.pagination.neurons-unchained') }}
    </div>
</div>

And this is the component logic

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Seizure;
use Carbon\Carbon;
use Livewire\WithPagination;

class Seizures extends Component
{

    use WithPagination;

    public $trash = false;
    public $filter;
    
    public function render()
    {

        //TODO: Get paginate number from user settings
        $seizures = Seizure::sortable(['date' => 'desc'])
            ->whereNull('deleted_at')
            ->where('note', 'like', '%' . $this->filter . '%')
            ->paginate(10);
            
        if( $this->trash) {
            $seizures = Seizure::sortable(['date' => 'desc'])
            ->whereNotNull('deleted_at')
            ->where('note', 'like', '%' . $this->filter . '%')
            ->paginate(10);
        }

        return view('livewire.seizure.index')
            ->with('seizures', $seizures->appends(\Request::except('page')))
            ->layout('layouts.dashboard');
    }

    public function delete(Seizure $seizure) {
        $seizure->deleted_at = Carbon::now();
        $seizure->save();

        $this->gotoPage(1);
    }

    public function toggleTrash () {
        $this->trash = !$this->trash;
    }
}

The toggle button for show elements in trash has same problem

Many thanks

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.