php - Bool is returning an array causing true response every time in Laravel 5.2 -
i getting true return query in laravel 5.2. making query in controller , returning array.
if($term = $request->get('term')){ $booking = guests::where('booking', '=', $term)->get(); $active = guests::where('booking', '=', $term)->pluck('active'); } // dd($active); if($active){ echo '
i have read potentially solved attribute casting attempts have not worked.
thanks
both get() , pluck() return collection, making if condition 1 doing - not return false if collection empty (collection method isempty() return false though). result of if ($active)
in code has nothing value of 'active' field itself.
you can try adding first() chain, assuming have or need 1 item:
$booking = guests::where('booking', '=', $term)->get()->first(); $active = guests::where('booking', '=', $term)->pluck('active')->first();