From 1f77b87331e2db8ccb3cce8012fbe8bfe0ea5b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 3 Sep 2020 11:14:24 +0200 Subject: [PATCH] Refactor quotes-table for simple model bind --- app/Http/Livewire/QuotesTable.php | 26 +++---------------- .../livewire/quotes-table.blade.php | 8 +++--- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/app/Http/Livewire/QuotesTable.php b/app/Http/Livewire/QuotesTable.php index 9bf687da3764..356e552a99d8 100644 --- a/app/Http/Livewire/QuotesTable.php +++ b/app/Http/Livewire/QuotesTable.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire; use App\Models\Quote; use App\Utils\Traits\WithSorting; +use Illuminate\Support\Facades\DB; use Livewire\Component; use Livewire\WithPagination; @@ -15,34 +16,13 @@ class QuotesTable extends Component public $per_page = 10; public $status = []; - public function statusChange($status) - { - if (in_array($status, $this->status)) { - return $this->status = array_diff($this->status, [$status]); - } - - array_push($this->status, $status); - } - public function render() { $query = Quote::query() ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc'); - if (in_array('draft', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_DRAFT); - } - - if (in_array('sent', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_SENT); - } - - if (in_array('approved', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_APPROVED); - } - - if (in_array('expired', $this->status)) { - $query = $query->orWhere('status_id', Quote::STATUS_EXPIRED); + if (count($this->status) > 0) { + $query = $query->whereIn('status_id', $this->status); } $query = $query diff --git a/resources/views/portal/ninja2020/components/livewire/quotes-table.blade.php b/resources/views/portal/ninja2020/components/livewire/quotes-table.blade.php index c357b5405cb0..3ac7fa16be55 100644 --- a/resources/views/portal/ninja2020/components/livewire/quotes-table.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/quotes-table.blade.php @@ -11,19 +11,19 @@
- +
- +
- +
- +