Files
radicall/app/Exports/PetExport.php
T

39 lines
1.1 KiB
PHP

<?php
namespace App\Exports;
use App\Models\Pet;
use Maatwebsite\Excel\Concerns\FromCollection;
class PetExport implements FromCollection
{
protected $filters;
public function __construct($filters = [])
{
$this->filters = $filters;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return Pet::when(isset($this->filters['search']) , function ($query){
$query->where(function ($q) {
$q->where('id', 'LIKE', "%{$this->filters['search']}%")
->orWhere('name', 'LIKE', "%{$this->filters['search']}%");
});
})
->when(isset($this->filters['type']) && $this->filters['type'] != 'همه نوع ها', function ($query) {
$query->whereIn('type' , $this->filters['type']);
})
->when(isset($this->filters['gender']) && $this->filters['gender'] != 'همه جنسیت ها', function ($query) {
$query->where('gender' , $this->filters['gender']);
})
->latest()
->get();
}
}