Skip to content

Instantly share code, notes, and snippets.

@FWSimon
Last active March 6, 2016 16:47
Show Gist options
  • Save FWSimon/917e459b304bc6e99f35 to your computer and use it in GitHub Desktop.
Save FWSimon/917e459b304bc6e99f35 to your computer and use it in GitHub Desktop.
return invoiceItems
public function Preview(Request $request)
{
$inputs = $request->all();
$quantity = $inputs['quantity'];
$description = $inputs['description'];
$price = $inputs['price'];
dd($inputs);
$client = Client::find($inputs['client']);
return view('invoices.preview', compact('inputs', 'client', 'invoiceItems'));
}
My `dd()` return this
array:9 [▼
"_token" => "1ReVum1ccihEpDgVIybxDinMGqv9EvfkziNQ41gP"
"client" => "1"
"day" => "5"
"month" => "2"
"year" => "2016"
"notes" => "sfsdfdsfs"
"quantity" => array:3 [▼
0 => "1"
1 => "1"
2 => "1"
]
"description" => array:3 [▼
0 => "sdfsdfd"
1 => "sfsfdsdf"
2 => "bvcbcvv"
]
"price" => array:3 [▼
0 => "2322"
1 => "2321"
2 => "2222"
]
]
@greew
Copy link

greew commented Mar 6, 2016

Hvad med en

$inputs = $request->all();

$invoiceItems = [];
$numInvoiceItems = count($inputs['quantity']);
for ($i = 0; $i < $numInvoiceItems; $i++) {
    $invoiceItems[] = [
        'quantity' => $inputs['quantity'][$i],
        'description' => $inputs['description'][$i],
        'price' => $inputs['price'][$i],
    ];
}

eller måske mere Laravel agtigt (jeg har aldrig kodet Laravel, så sig til hvis jeg tager fejl)

$inputs = $request->all();

$invoiceItems = collection($inputs['quantity']);
$invoiceItems->zip(collection($inputs['description']);
$invoiceItems->zip(collection($inputs['price']);

hvor hhv. quantity, description og price vil lægge i element 0, 1 og 2 i dit array... (ud fra hvad jeg lige kan læse i Laravel docs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment