Skip to content

Instantly share code, notes, and snippets.

@FWSimon
Created March 9, 2016 17:59
Show Gist options
  • Save FWSimon/395a103141a3de413274 to your computer and use it in GitHub Desktop.
Save FWSimon/395a103141a3de413274 to your computer and use it in GitHub Desktop.
public function Preview(Request $request)
{
$inputs = $request->all();
$invoiceItems = array_map(function ($quantity, $description, $price) {
return [
'quantity' => $quantity,
'description' => $description,
'price' => $price
];
}, $inputs['quantity'], $inputs['description'], $inputs['price']);
$client = Client::find($inputs['client']);
//combine dates
$due_date = $request->year .'-'.$request->month .'-'.$request->day;
//Save invoice
$invoice = new Invoice;
$invoice->client_id = $request->client;
$invoice->user_id = Auth::user()->id;
$invoice->due_date = $due_date;
$invoice->status = 'created';
$invoice->amount = $request->amount;
$invoice->save();
foreach ($invoiceItems as $invoiceItem)
{
$invoiceDB = new InvoiceItem;
$invoiceDB->invoice_id = $invoice->id;
$invoiceDB->quantity = $invoiceItem['quantity'];
$invoiceDB->description = $invoiceItem['description'];
$invoiceDB->price = $invoiceItem['price'];
$invoiceDB->save();
}
return view('invoices.preview', compact('inputs', 'client', 'invoiceItems'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment