mercredi 11 juillet 2018

Laravel - Trying to get property of non-object - PHP

I am currently trying to learn Laravel and PHP in general.

I need to be able to import an Excel file, then get the data from that file. Currently, the import part works and I can see the data from the file. However, I am having trouble accessing the data.

I've read about the toArray() function in Laravel, and is using that as below:

 $data = Excel::load($path, function($reader) {})->skipColumns(2)->get();
 $data = $data->toArray();

         foreach ($data as $key => $value) {

           //We only need some of the available data.
           echo $value->next_milestone_desc_cur._comp._incl_rltd;
           echo $value->shipment_id;

          }

Above code gives me below error:

Trying to get property 'next_milestone_desc_cur' of non-object

Below is an output from the array, which I have generated using dd($value):

array:543 [▼
  0 => array:20 [▼
    "next_milestone_desc_cur._comp._incl_rltd" => "005. DK - Add DropMode/Local Trp Org in Pickup Tab"
    "milestone_cur._comp._sequence_no" => "005"
    "cur._comp._export_validation" => "NOT OK"
    "shipment_id" => "SBRY0162091"
    "consol_id" => "CDK327188"  ]
  1 => array:20 [▼
    "next_milestone_desc_cur._comp._incl_rltd" => "005. DK - Add DropMode/Local Trp Org in Pickup Tab"
    "milestone_cur._comp._sequence_no" => "005"
    "cur._comp._export_validation" => "NOT OK"
    "shipment_id" => "SBRY0162124"
    "consol_id" => "CDK327221"
  ]

What am I doing wrong here? I have also tried echo $value[0]->next_milestone_desc_cur._comp._incl_rltd;, however this doesn't work either.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire