⚝
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 :
Projects.php
<?php namespace App\Http\Livewire; use App\Models\Project; use App\Repositories\ProjectRepository; 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 Projects extends SearchableComponent { public $statusFilter = ''; public $billingType = ''; public $customer = ''; /** * @return Application|Factory */ public function render() { $projects = $this->searchProjects(); $projectRepo = app(ProjectRepository::class); $data['statusCount'] = $projectRepo->getProjectsStatusCount($this->customer); $data['search'] = ''; $data['customer'] = $this->customer; $data['projectStatusArr'] = Project::STATUS; return view('livewire.projects', [ 'projects' => $projects, ])->with($data); } /** * @return LengthAwarePaginator */ public function searchProjects() { $this->setQuery($this->getQuery()->with(['customer', 'members.user.media', 'projectContacts', 'tags'])); $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->billingType !== '', function (Builder $q) { $q->where('billing_type', $this->billingType); }); $this->getQuery()->when($this->customer !== '', function (Builder $q) { $q->where('customer_id', $this->customer); }); return $this->paginate(); } /** * @param $projectId */ public function deleteProject($projectId) { $project = Project::find($projectId); activity()->performedOn($project)->causedBy(getLoggedInUser()) ->useLog('Project deleted.')->log($project->project_name.' Project deleted.'); $project->delete(); $project->members()->delete(); $this->dispatchBrowserEvent('deleted'); $this->searchProjects(); } public function filterProjectsByStatus($projectId) { $this->statusFilter = $projectId; $this->resetPage(); } public function filterProjectsByBillingType($projectId) { $this->billingType = $projectId; $this->resetPage(); } /** * @var string[] */ protected $listeners = [ 'refresh' => '$refresh', 'deleteProject', 'filterProjectsByStatus', 'filterProjectsByBillingType', ]; /** * @return string */ public function model() { return Project::class; } /** * @return string[] */ public function searchableFields() { return [ 'project_name', 'customer.company_name', ]; } /** * @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(); } public function updatingSearch() { $this->resetPage(); } }