Please find below Code. I have used foreach to handle multiple data. But, It is giving me error in JSON response. Any help ?
public function import(Request $request) {
foreach ($request as $requests) { $pickup = new Pickup();
if ($requests->status == 1) {
$pickup->status = 'Published';
} else { //if 0 then unpublished
$pickup->status = 'UnPublished';
}
if ($requests->fc_id != null && $requests->fc_id != 0) {
$pickup->status = 'Accepted';
}
if ($requests->fc_id != null && $requests->fc_id != 0) {
$pickup->agent_id = $requests->fc_id;
} else {
$pickup->agent_id = Null;
}
$pickup->customer_id = $requests->customer_id;
$pickup->product_id = $requests->product_id;
$pickup->price = $requests->price;
$pickup->pickup_person = $requests->pickup_person;
$pickup->pickup_email = $requests->pickup_email;
$pickup->application_id = $requests->application_id;
$pickup->home_address = $requests->home_address;
$city = ucfirst(trim($requests->city));
$city = ucfirst(strtolower($city));
$pickup->city = $city;
$pickup->state = $requests->state;
$pickup->pincode = $requests->pincode;
$pickup->office_address = $requests->office_address;
$pickup->office_city = $requests->office_city;
$pickup->office_state = $requests->office_state;
$pickup->office_pincode = $requests->office_pincode;
$pickup->mobile = $requests->mobile;
$pickup->cheque_amt = $requests->cheque_amt;
$pickup->loan_amt = $requests->loan_amt;
$pickup->preferred_start_time = $requests->preferred_start_time;
$pickup->preferred_end_time = $requests->preferred_end_time;
$saved = $pickup->save();
if ($saved) {
return Response::json(array(
'error' => 0,
'message' => 'Data Inserted Successfully !'), 200
);
} else {
return Response::json(array(
'error' => 1,
'message' => 'Data Not Inserted. Please try again !'), 201
);
}
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire