lundi 2 juillet 2018

Import Excel Using Laravel Excel (Maat)

Hi I have an excel file with the details of passengers under the trip ID. I want to import that excel file in my table. please see the picture below: enter image description here

the first row with the blue color is my column names on my table. my problem is how can I save the value of D2:G2 in next_of_kin table with this kind of format.

[
 {"name":James Lara,"mobile":12345678},
 {"name":Jasmine Lara,"mobile":12345678}
]

enter image description here

this is my code on my controller.

// Get excel file
$path = $request->file;

// Save the content to passenger
Excel::load($path, function ($reader) use ($request) {

 $trip = Trip::where('id', $request->trip_customer_id)->first();

 foreach ($reader->toArray() as $row) {
   $trip->passengers()->create($row);
 }

});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire