Reputation: 17
I want to send 'Date' array from a page to another page through checkbox input for display the data and get more data from database.
I try to dd() the array from input, it's still normal but the data just only show 1 value when I use 'foreach' loop. How do I do?
<input name="isInvoices[]" type="checkbox" value="{{ $date }}">
$invoices = $request->input('isInvoices');
// dd($invoice); It's show array of date
foreach($invoices as $invoice) {
dd($invoice); //It's just only 1 value
}
I expected the output to show all value in the array, but the actual output is show 1 value.
Upvotes: 0
Views: 80
Reputation: 3951
dd() – stands for “Dump and Die”, and it means as soon as loop gets to this command, it will stop executing the program, in this case in first interation. To display all data in foreach loop, use echo or print_r():
foreach($invoices as $invoice) {
echo $invoice;
}
This means that the program will print $invoice for each iteration. Then you can access your data like this:
$invoice['value']
You can read more about different types of echoing here.
Upvotes: 0
Reputation: 902
before such would function, you have to have series of checkbox like:
this is display series of date values on checkbox. so when you select any dates and submit
foreach($datevalue as $date){
<input name="isInvoices[]" type="checkbox" value="{{ $date }}">
}
//this gets the date value
$invoices = $request->input('isInvoices');
//this will display all the selected checkboxes
foreach($invoices as $invoice) {
dd($invoice);
}
Upvotes: 0
Reputation: 14268
dd
means dump
and die
. Which after the first iteration stops, that's why you see only one item. Try this:
foreach($invoices as $invoice) {
dump($invoice);
}
die;
Upvotes: 1