When I toggle manage_invoice, to ON, the back end updates and also the frontend, but when I refresh, the frontend is bakc to OFF, while still the backend boolean is 1. Why doesn't the fronted display ON after refresh?
UsersList.php:
<?php
namespace App\Livewire;
use App\Models\Team;
use App\Models\TeamUser;
use App\Models\User;
use Auth;
use Illuminate\Contracts\View\View;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Attributes\Url;
use Livewire\Component;
class UsersList extends Component
{
use LivewireAlert;
public ?User $user = null;
public array $invoice = [];
public function toggleManageInvoice(int $userId): void
{
if (Auth::user()->is_admin) {
TeamUser::where([
'id' => $userId,
])->update([
'manage_invoice' => $this->invoice[$userId],
]);
}
}
public function render(): View
{
$users = TeamUser::query()
->select([
'team_user.*'
]);
#dd($users->get());
$this->invoice = $users->pluck('manage_invoice', 'id')->toArray();
return view('livewire.users-list', [
'users' => $users->paginate(10)
]);
}
}