0

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.

2
  • use echo $invoice; instead of dd($invoice); Commented Jun 11, 2019 at 7:42
  • Well of course $invoice is one value from the array $invoices which is the array that comes from input('isInvoices') Commented Jun 11, 2019 at 8:09

3 Answers 3

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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); 
   }

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.