In my Controller, I have the following.
public function check_login(Request $request)
{
$users = User::all('user_type');
if ($users === 'teacher') {
echo 'teacher';
} else if ($users === 'student') {
echo 'student';
} else {
echo 'nothing';
}
}
Unfortunately, the if
and else if
are not working.
When you use the method All()
you're getting the whole collection. Try loop the $users
like this:
$users = User::all();
foreach($users as $user)
{
if($user->user_type == 'teacher')
{
echo 'teacher';
}
else if($user->user_type == 'student'){
echo 'student';
}
else{
echo 'nothing';
}
}
Here you're comparing each object from the User Collection
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments