Home > Enterprise >  how to use count() in controller?
how to use count() in controller?

Time:04-20

How do I get the number of rows here? When I use $count = $flights->count(); I get this error Count all elements in an array, or something in an object

public function index(Request $request)
        {
            $airline  = airline::all(); 
            $search = $request->get('search');
                    if($search!=""){
                        $flights =  DB::table('flights')
                        ->join('airlines', 'flights.AirlineId', '=', 'airlines.id')
                        ->select('flights.*', 'airlines.name', 'airlines.country','airlines.logo')
                        ->where(DB::raw("CONCAT(flights.id,' ',flights.flightDesignator,' ',airlines.country,' ',airlines.name,' ',flights.departureFrom,' ',flights.arriveTo,' ',flights.departureTime,' ',flights.ArrivalTime)"),'LIKE','%'.$search.'%')
                        ->paginate(4);
                $flights->appends(['search' => $search]);
                $count = $flights->count();
                if($count == 0)
                return view('admin.flights')->with(['flights' => $flights,'airline' => $airline, 'NoFound' => 'There is no result            
  • Related