/** * Store a newly created resource in storage. * * @return Response */ public function store() { try { $admin = \Auth::User(); if (!$admin) { return $this->failResponse('admin not logged in'); } $invoiceObj = new Invoice(); $data = $this->getRequestBody(); $invoiceObj->customer_id = $data['customer_id']; $invoiceObj->attn = $data['attn']; $invoiceObj->invoice_number = $data['invoice_number']; $invoiceObj->description = $data['description']; $invoiceObj->save(); if (!$invoiceObj->save()) { Log::error("error in saving"); $errors = $invoiceObj->getErrors(); return $this->failResponse('Validation failed. Cannot save data.' . $errors); } else { return $this->successResponse('updated sucessfully'); } } catch (\Exception $e) { Log::error($invoiceObj->getErrors()); return $this->failResponse($e->getMessage()); } }