ponnydalen
2 months ago
232
2
Laravel

Where clause from API array

Posted 2 months ago by ponnydalen

Hello. I am getting data into a Datatable from here:

$flightData = file_get_contents("https://avinor.no/Api/Flights/Airport/OSL?direction=a&start={$dateStart}T22:00:00Z&end={$dateEnd}T21:59:59Z&language=no");

Then I do

        $flightData = json_decode($this->getFlightData());

        $flights = $flightData->Flights;
        
        dd($flights);

And I get this:

 array:144 [
            0 => {#1276
              +"Id": "sk1474-cph-osl-20200706"
              +"AirlineName": "SAS"
              +"AirportNameToOrFrom": "København"
              +"AirportToOrFrom": "CPH"
              +"CodeShares": []
              +"FlightId": "SK1474"
              +"FromAirport": "CPH"
              +"FromAirportName": "København"
              +"Gate": null
              +"Belt": null
              +"GateOrBelt": null
              +"GateOrBeltStatus": null
              +"IsDeparture": false
              +"IsOld": true
              +"ScheduleChanged": false
              +"ScheduledTime": "00:10"
              +"ScheduledTimeFull": "202007070010"
              +"Status": "Landet 23:47"
              +"ToAirport": "OSL"
              +"ToAirportName": "Oslo"
              +"Date": "20200707"
              +"CheckInZones": null
              +"Timestamp": 1594073400
            }
            1 => {#1277
              +"Id": "wf180-fde-osl-20200707"
              +"AirlineName": "Widerøe"
              +"AirportNameToOrFrom": "Førde"
              +"AirportToOrFrom": "FDE"
              +"CodeShares": []
              +"FlightId": "WF180"
              +"FromAirport": "FDE"
              +"FromAirportName": "Førde"
              +"Gate": null
              +"Belt": null
              +"GateOrBelt": null
              +"GateOrBeltStatus": null
              +"IsDeparture": false
              +"IsOld": true
              +"ScheduleChanged": false
              +"ScheduledTime": "07:25"
              +"ScheduledTimeFull": "202007070725"
              +"Status": "Landet 07:16"
              +"ToAirport": "OSL"
              +"ToAirportName": "Oslo"
              +"Date": "20200707"
              +"CheckInZones": null
              +"Timestamp": 1594099500
            }
        ]

It's working good if I want to get all the result into the datatable, BUT I want to only get the results that has "IsOld" = false .

I've tried this

$result= DB::table($flights)->where('IsOld', false)->get();
        
        dd($result);

But it gives me "Array to string conversion" How can I achieve this?

Please sign in or create an account to participate in this conversation.