Created
March 9, 2016 17:59
-
-
Save FWSimon/395a103141a3de413274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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