37 lines
930 B
PHP
37 lines
930 B
PHP
<?php
|
|
|
|
namespace App\ModelFilters;
|
|
|
|
use App\Models\AdminUser;
|
|
use EloquentFilter\ModelFilter;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class AgriculturalBaseFilter extends ModelFilter
|
|
{
|
|
public function type($type)
|
|
{
|
|
return $this->where('type', $type)
|
|
->when($type == 1, function ($builder) {
|
|
$user = Auth::user();
|
|
|
|
if ($user instanceof AdminUser && ! $user->isAdministrator() && ! $user->view_all_bases) {
|
|
$builder->whereRaw("id in (select base_id from admin_user_bases where user_id = {$user->id})");
|
|
}
|
|
});
|
|
}
|
|
|
|
public function parent($parent)
|
|
{
|
|
return $this->where('parent_id', $parent);
|
|
}
|
|
|
|
public function name($name)
|
|
{
|
|
return $this->where('name', 'like', '%'.$name.'%');
|
|
}
|
|
|
|
public function industry($industry){
|
|
return $this->where('industry_key', $industry);
|
|
}
|
|
}
|