php - If statement never evaluates to true (even when it should) -
i'd created if statement "if ($user_roles == 3) " , $user_roles has value of "3" condition supposed true result false.
here code below:
public function viewsponsorinfo($sponsor_id) { $id = $sponsor_id; $user_id = user::where('id','=',$id)->get(); $user_roles = []; foreach ($user_id $id) { array_push($user_roles, $id->role); }/* dd($user_roles);*/ if ($user_roles == 3) { $orga = organization::where('orga_id','=',$sponsor_id)->get(); dd($orga); return view('pages.ngo.view-sponsor-information',compact('orga')); }else{ $indi = individual::where('indi_id','=',$sponsor_id)->get(); dd($indi); return view('pages.ngo.view-sponsor-information',compact('indi')); } }
$user_roles
is not 3 , can never be. it's array. contents, however, can three.
try:
if(in_array(3, $user_roles)) { ...}
for reference: in_array
Comments
Post a Comment