1

I have this bit of code in my form edit.blade.php :

@php
    $imagepath="images/Service/".$services->name."/";
    $images=glob($imagepath.'*.*');   
@endphp

<div class="row">
     @foreach($images as $image)
         @php
             $count++;
         @endphp

         <div class="col-md-5">
             <img src="{{URL::asset($image)}}"  style="height: 150px;object-fit: contain;">
         </div>
         <div class="col-md-1">
             <input form="services" type="checkbox"  name="deleteimagelink[]" value="{{($image)}}"  >
         </div>
    @endforeach
</div>

This is for passing the path of those images meant to be deleted. And I have this snippet in my controller:

print_r($request->input('deleteimagelink'));
$deletables=$request->input('deleteimagelink');
foreach ($deletables as $deletable)
{
    print_r($deletable);
    unlink($deletable);    
}

I have this problem that nothing is being received in the $request->input('deleteimagelink') parameter. Please guide me if I'm doing anything wrong. If nothing seems weird, can you please guide me how to deal with these checkbox situations in laravel. I consulted related answers from internet but nothing seems to work.

3
  • How are you submitting these inputs to the server? ajax? standard form? and (I know this is a stupid question - but gotta ask to be sure...) are any of the checkboxes actually 'checked'? Commented Sep 16, 2018 at 3:04
  • I'm using regular forms for submission. And yes, Ive checked varying number of checkboxes to check for it and the results are all same. Commented Sep 16, 2018 at 3:06
  • There are other elements in the form too, including new file uploads. All are well received in the controller but just this one Commented Sep 16, 2018 at 3:07

2 Answers 2

1
<form class="form-group" method="post" action="/destroy" enctype="multipart/form-data">
     @csrf
    <input type="checkbox"  name="deleteimagelink[]" value="1"  >
      <input type="checkbox"  name="deleteimagelink[]" value="2"  >
     <button class="btn btn-primary" type="submit">Actualizar</button
      </form>

Controller

public function destroy(Request $request) { return $request; }

{"_token":"BetJnyujXvJnpkkwDU31kYO7lVz5OqflMQDoCLQy","deleteimagelink":["1","2"]}

This Works for me!

Sign up to request clarification or add additional context in comments.

2 Comments

Im sending an array of deleteimagelink. The field is inside the foreach loop. So, it requires this [ ] Jose
Thank you Jose. But I figured out how I could get it right. {Still didn't get what wrong I was doing though.} ;) Cheers.
0

I had included the code above outside the <form></form> tag in order to justify to my view. Interestingly, it didn't work even though that I had included form="services" as a parameter in my input field{services is the form name here}. I had worked something like this before and it had worked pretty good that time. I managed to get the <form></form> tags outside the whole of my form elements and it is working fine now. Thank you everybody who tried to help.

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.