| Current Path : /home/forge/stage.sksb.smartcon-survey.com/app/Livewire/ |
| Current File : /home/forge/stage.sksb.smartcon-survey.com/app/Livewire/ContactsTable.php |
<?php
namespace App\Livewire;
use App\Models\Contact;
use Livewire\Component;
use Livewire\WithPagination;
class ContactsTable extends Component
{
use WithPagination;
public $search = '';
public $selected = [];
public $disableDelete = true;
public $paginationLimit = 10;
public function deleteSelectedContacts()
{
if (count($this->selected) > 0) {
Contact::destroy($this->selected);
}
}
public function render()
{
$this->disableDelete = count($this->selected) === 0;
return view('livewire.contacts-table', [
'contacts' => Contact::search($this->search)->with('department')
->orderBy('created_at', 'desc')
->simplePaginate($this->paginationLimit),
]);
}
public function toggleAllCheckboxes($checkboxStatus)
{
if (count($this->selected) > 0 || $checkboxStatus === false) {
$this->selected = [];
} else {
$contacts = Contact::search($this->search)->with('department_id')
->orderBy('created_at', 'desc')
->simplePaginate($this->paginationLimit);
foreach ($contacts as $contact) {
array_push($this->selected, $contact->id);
}
}
}
public function pageLimit($limit)
{
$this->paginationLimit = $limit;
}
}