So what you want to do is:
- Make a new array that holds arrays of users when it matches
- Then return that new array
Example:
$matchedUsers = array();
foreach($results as $result) {
// Value may be 1,2,3 etc
if($result->id == $value) {
$matchedUsers[] = User::whereId($value)->get();
}
}
return view('index', compact('matchedUsers'));
An even cleaner way to do this is to have a seperate function that does your call for User Info when it matches:
public function getUsers($results)
{
$matchedUsers = array();
foreach($results as $result){
// Value may be 1,2,3 etc
if($result->id == $value) {
$matchedUsers[] = User::whereId($value)->get();
}
}
return view('index', compact('matchedUsers'));
}
public function getMatchedUser($userId)
{
return User::whereId($userId)->get();
}