⚝
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 :
Proposals.php
<?php namespace App\Http\Livewire; use App\Models\Customer; use App\Models\Lead; use App\Models\Proposal; use App\Repositories\ProposalRepository; 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 Proposals extends SearchableComponent { public $statusFilter = ''; public $customer = ''; public $lead = ''; /** * @var string[] */ protected $listeners = [ 'refresh' => '$refresh', 'filterProposalStatus', ]; /** * @return string */ public function model() { return Proposal::class; } /** * @return string[] */ public function searchableFields() { return [ 'title', 'proposal_number', ]; } /** * @return Application|Factory */ public function render() { $proposals = $this->searchProposals(); $proposalRepo = app(ProposalRepository::class); $statusCount = $proposalRepo->getProposalsStatusCount(); $customer = $this->customer; $lead = $this->lead; $proposalStatus = Proposal::STATUS; return view('livewire.proposals', compact('proposals', 'statusCount', 'customer', 'proposalStatus')); } /** * @return LengthAwarePaginator */ public function searchProposals() { $this->setQuery($this->getQuery()->with(['customer', 'lead'])); $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('owner_id', $this->customer) ->where('owner_type', Customer::class); }); $this->getQuery()->when($this->lead !== '', function (Builder $q) { $q->where('owner_id', $this->lead) ->where('owner_type', Lead::class); }); 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 filterProposalStatus($id) { $this->statusFilter = $id; $this->resetPage(); } public function updatingSearch() { $this->resetPage(); } }