complete Complete User Request Submission section RAD-1
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class DocumentExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Document::with(['pet', 'requester'])->when(isset($this->filters['search']) , function ($query){
|
||||
$query->where(function ($q){
|
||||
$q->where('code', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('id', $this->filters['search'])
|
||||
->orWhereHas('requester', function ($userQuery) {
|
||||
$userQuery->where('fullname', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('username', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('email', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('phone', 'LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(isset($this->filters['status']), function ($query) {
|
||||
$query->where('status' , DocumentStatusEnum::fromName($this->filters['status'])->value );
|
||||
})
|
||||
->when(isset($this->filters['priority']), function ($query) {
|
||||
$query->where('priority' , DocumentPriorityEnum::fromName($this->filters['priority'])->value);
|
||||
})
|
||||
->when(isset($this->filters['pet']), function ($query) {
|
||||
$query->where('pet_id' , $this->filters['pet']);
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user