37 lines
914 B
PHP
37 lines
914 B
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\User;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
|
|
class UsersExport implements FromCollection
|
|
{
|
|
|
|
protected $filters;
|
|
|
|
public function __construct($filters = [])
|
|
{
|
|
$this->filters = $filters;
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
public function collection()
|
|
{
|
|
return User::when(isset($request->search) , function ($query){
|
|
$query->where(function ($q) {
|
|
$q->where('name', 'LIKE', "%{$this->filters['search']}%")
|
|
->orWhere('email','LIKE', "%{$this->filters['search']}%");
|
|
});
|
|
})
|
|
->when(isset($this->filters['level']) && $this->filters['level'] != 'همه سطح ها', function ($query) {
|
|
$query->where('level' , $this->filters['level']);
|
|
})
|
|
->latest()
|
|
->get();
|
|
}
|
|
}
|