public static function filter($visa_type, $status, $company)
{
if (Auth::user()->hasRole('administrator|Manager')) {
if ($visa_type && $status & $company) {
return self::where('visa_type', $visa_type)
->where('status', $status)
->where('company', $company)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type && $status) {
return self::where('visa_type', $visa_type)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type && $company) {
return self::where('visa_type', $visa_type)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($status && $company) {
return self::where('company', $company)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type) {
return self::where('visa_type', $visa_type)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($status) {
return self::where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else {
return self::where('company', $company)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
}
} else {
if ($visa_type && $status & $company) {
return self::where('user_id', Auth::user()->id)
->where('visa_type', $visa_type)
->where('status', $status)
->where('company', $company)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type && $status) {
return self::where('user_id', Auth::user()->id)
->where('visa_type', $visa_type)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type && $company) {
return self::where('user_id', Auth::user()->id)
->where('visa_type', $visa_type)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($status && $company) {
return self::where('user_id', Auth::user()->id)
->where('company', $company)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($visa_type) {
return self::where('user_id', Auth::user()->id)
->where('visa_type', $visa_type)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else if ($status) {
return self::where('user_id', Auth::user()->id)
->where('status', $status)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
} else {
return self::where('user_id', Auth::user()->id)
->where('company', $company)
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];
}
}
}
public function scopeFilter($query, $parameters = []){
$fields = ['visa_type', 'status', 'company'];
$filter = collect([
'visa_type' => null,
'status' => null,
'company' => null,
'paginate' => 40,
'order' => 'id',
'sort' => 'desc'
])->merge($parameters);
if (!Auth::user()->hasRole('administrator|Manager')) {
$query->where('user_id', Auth::user()->id);
}
foreach($filter->only($fields) as $field => $value){
$query->where($field, $value);
}
return $query
->orderBy($filter->get('order'), $filter->get('sort'))
->paginate($filter->get('paginate'))
->toArray()['data'];
}
SomeModel::where(...)->filter([
'visa_type' => '....',
'paginate' => 20,
'sort' => 'asc'
]);
$dataProvider = new self(); //вот этот момент надо проверить
if ($visa_type) {
$dataProvider->where('visa_type', $visa_type);
}
if ($status) {
$dataProvider->where('status', $status);
}
...
return $dataProvider->orderBy('id', 'desc')
->paginate(40)
->toArray()['data']
if ($visa_type && $status & $company) {
public static function filter($visa_type, $status, $company)
{
$query = self::query();
if (!Auth::user()->hasRole('administrator|Manager')) {
$query->where('user_id', Auth::user()->id);
}
if ($visa_type) {
$query->where('visa_type', $visa_type);
}
if ($status) {
$query->where('status', $visa_type);
}
if ($company) {
$query->where('company', $company);
}
return $query
->orderBy('id', 'desc')
->paginate(40)
->toArray()['data'];