I\'m trying to redirect the user to another page if my additional_infos table contain some stuff that are empty in this case, contact, name and address.
I\'ve done somet
Try transform your query to SQL to check what are you doing with database first
$additional_info = DB::table('additional_infos')->where('address',NULL)->orWhere('name', NULL)->orWhere('number')->toSql();
dd($additional_info);
You will never get null so that you can test it in if like this if( $additional_info)
it will alawys evaluate to true, because it will always return a collection even if there is no elements that fulfil the conditions it will return a empty collection not null.
You have three choices :
Use ->get()
and add ->count()
in the if statment if($additional_info->count())
Replace ->get()
by ->first()
and leave if($additional_info)
Replace ->get()
by ->count()
and if($additional_info > 0)
Try it using whereNull
and orWhereNull
like this :
public function test(Request $request){
$additional_info = DB::table('additional_infos')
->whereNull('address')
->orWhereNull('name')
->orWhereNull('number')
->get();
//request input //ignore this part
if( $additional_info->count())
return redirect(url('/user/showupdate6/'.$id->id.'/edit6') );
else{
return redirect('/home');
}