where('time_year', $y); } public function quarter($quarter){ return $this->where('quarter', $quarter); } public function crop($cropId) { return $this->where('crop_id', $cropId); } public function type($type) { return $this->whereHas('base', function($q) use ($type) { return $q->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})"); } })->where('type', $type); }); } }