Laravel foreach seems to stop at the first record
You use return
so that breaks your function.
if($admin->id == \Auth::user()->id) {
// do something else but don't return
}
By returning a value you instantly exit the function so that is the reason that only your 1st loop works.
Inside your loop you always return true/false so the 1st iteration for sure will send you out.
A nicer solution and will work for what you are trying to do is to use array functions to search inside your admin collection.
Since you are using collections you can use collection helpers from laravel to search inside your collection without using a foreach
loop
if($this->application->admins->search(\Auth::user()->id)){
return true;
}
This always returns on the first loop. Move the return false
down a line.
public function isTaskAppAdmin()
{
foreach($this->application->admins as $admin) {
if($admin->id == \Auth::user()->id) {
return true;
}
}
return false;
}