Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

multiple checked delete in laravel8

//web.php
Route::post('/contact-bulk-action',[ContactController::class,'bulkAction'])->name('contact.bulkAction');

//_Controller.php
public function bulkAction(IlluminateHttpRequest $request){
        Contact::destroy($request->contact_ids);
        return redirect()->back();
    }
    
//_.blade.php
 <form action="{{route('contact.bulkAction')}}" id="bulk_action" method="post">
 	@csrf
 </form>
<ul class="list-group">
  @forelse($contacts as $contact)
  <li class="list-group-item d-flex justify-content-between align-items-center">
    <div class="">
      <div class="form-check">
        <input type="checkbox" form="bulk_action" name="contact_ids[]"  value="{{$contact->id}}" id="contact{{ $contact->id  }}">
        <label for="contact{{ $contact->id  }}">
        {{$contact->name}}
        </label>
      </div>
    </div>
  </li>
  @empty
  <li>
  	There is no data
  </li>
  @endforelse
</ul>
 
PREVIOUS NEXT
Tagged: #multiple #checked #delete
ADD COMMENT
Topic
Name
7+4 =