Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trifek's avatar

Array to collection

Hi, I have small problem with convert array to collection in Laravel.

I have this code:

$this->inpostService->getTracking('605850699284230016546816');

this return me:

public function getTracking(string $parcelNumber)
    {
        $url = 'https://api-shipx-pl.easypack24.net/v1/tracking/'.$parcelNumber;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($ch);
        dd($result);
    }

I have result:

{"tracking_number":"605850699284230016546816","service":"inpost_locker_standard","type":"inpost_locker_standard","status":"ready_to_pickup","custom_attributes":{"size":"A","target_machine_id":"RUM12M","target_machine_detail":{"name":"RUM12M","opening_hours":"24/7","location_description":"Przy Myjni Bezdotykowej Rumia Kosynierów 79l","location":{"latitude":54.58517,"longitude":18.37872},"address":{"line1":"Kosynierów 79l","line2":"84-230 Rumia"},"type":["parcel_locker"],"location247":true},"end_of_week_collection":false},"tracking_details":[{"status":"ready_to_pickup","origin_status":"UWP","agency":null,"datetime":"2022-01-07T11:08:37.000+01:00"},{"status":"out_for_delivery","origin_status":"PDD_2","agency":null,"datetime":"2022-01-07T08:57:27.000+01:00"},{"status":"adopted_at_source_branch","origin_status":"PWO","agency":null,"datetime":"2022-01-06T07:47:56.000+01:00"},{"status":"adopted_at_source_branch","origin_status":"PWO","agency":null,"datetime":"2022-01-06T07:16:32.000+01:00"},{"status":"adopted_at_source_branch","origin_status":"PWO","agency":null,"datetime":"2022-01-06T07:15:05.000+01:00"},{"status":"sent_from_source_branch","origin_status":"WZO","agency":null,"datetime":"2022-01-05T23:41:35.000+01:00"},{"status":"sent_from_source_branch","origin_status":"WZO","agency":null,"datetime":"2022-01-05T20:50:43.000+01:00"},{"status":"collected_from_sender","origin_status":"PKL","agency":null,"datetime":"2022-01-05T16:57:49.000+01:00"},{"status":"confirmed","origin_status":"PPN","agency":null,"datetime":"2022-01-04T20:05:33.000+01:00"}],"expected_flow":[],"created_at":"2022-01-04T20:05:33.783+01:00","updated_at":"2022-01-07T11:08:43.321+01:00"}

How can I convert to collection?

Please help me.

0 likes
5 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

It looks like json

        dd(collect(json_decode($result)));
trifek's avatar

It's working :)

I have second question. When I make this code:

$this->inpostService->getTracking(605850699284230016546816);
public function getTracking(string $parcelNumber)
    {   dd($parcelNumber);
}

I have return: 6.0585069928423E+23 - why not complete: 605850699284230016546816 ?

Please or to participate in this conversation.