I'm trying to get all the users where a given method in User
model meets. Please see my code below:
User.php
public function isPicker(){
return ($this->where('isPicker', 1)) ? true : false;
}
Now, I can use User::all();
, but it returns all the users. What I want is to only return the users that meets the isPicker()
method. What I'm trying to do in view is:
@foreach($users as $user)
@if($user->isPicker())
{{ $user->first_name }}
@endif
@endforeach
This is also working fine, but it is not that efficient to use. What if there's a lot of method to check? Any idea for this?