⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
crm.dev-unit.com
/
app
/
Http
/
Livewire
/
View File Name :
Estimates.php
<?php namespace App\Http\Livewire; use App\Models\Estimate; use App\Repositories\EstimateRepository; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Contracts\View\Factory; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; class Estimates extends SearchableComponent { public $statusFilter = ''; public $customer = ''; /** * @var string[] */ protected $listeners = [ 'refresh' => '$refresh', 'filterEstimateStatus', ]; /** * @return string */ public function model() { return Estimate::class; } /** * @return string[] */ public function searchableFields() { return [ 'title', 'estimate_number', 'customer.company_name', ]; } /** * @return Application|Factory */ public function render() { $estimates = $this->searchEstimates(); $estimatesRepo = app(EstimateRepository::class); $statusCount = $estimatesRepo->getEstimatesStatusCount(); $customer = $this->customer; $estimateStatus = Estimate::STATUS; return view('livewire.estimates', compact('estimates', 'statusCount', 'customer', 'estimateStatus')); } /** * @return LengthAwarePaginator */ public function searchEstimates() { $this->setQuery($this->getQuery()->with('customer')); $this->getQuery()->where(function (Builder $query) { $this->filterResults(); }); $this->getQuery()->when($this->statusFilter !== '', function (Builder $q) { $q->where('status', $this->statusFilter); }); $this->getQuery()->when($this->customer !== '', function (Builder $q) { $q->where('customer_id', $this->customer); }); return $this->paginate(); } /** * @return Builder */ public function filterResults() { $searchableFields = $this->searchableFields(); $search = $this->search; $this->getQuery()->when(! empty($search), function (Builder $q) use ($search, $searchableFields) { $this->getQuery()->where(function (Builder $q) use ($search, $searchableFields) { $searchString = '%'.$search.'%'; foreach ($searchableFields as $field) { if (Str::contains($field, '.')) { $field = explode('.', $field); $q->orWhereHas($field[0], function (Builder $query) use ($field, $searchString) { $query->whereRaw("lower($field[1]) like ?", $searchString); }); } else { $q->orWhereRaw("lower($field) like ?", $searchString); } } }); }); return $this->getQuery(); } /** * @param int $id */ public function filterEstimateStatus($id) { $this->statusFilter = $id; $this->resetPage(); } public function updatingSearch() { $this->resetPage(); } }