PHP Laravel 5.6 Delete Multiple Rows using Checkbox

Today, We want to share with you PHP Laravel 5.6 Delete Multiple Rows using Checkbox.In this post we will show you php – Laravel 5.6 delete multiple checkbox, hear for Delete Multiple Data using Checkbox in Laravel 5.6 we will give you demo and example for implement.In this post, we will learn about How to Delete Multiple Records Using Laravel Eloquent with an example.

PHP Laravel 5.6 Delete Multiple Rows using Checkbox

There are the Following The simple About PHP Laravel 5.6 Delete Multiple Rows using Checkbox Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to delete multiple rows with checkbox using jquery ajax in PHP Laravel 5.6 with demo, so the some major files and Directory structures for this example is following below.

  • Create MySQL TABLE
  • Create Laravel Model
  • Controller
  • View

Step1: Make database table

create a progammings table on MySQL

CREATE TABLE `progammings` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `progamming_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `progamming_details` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

INSERT INTO `progammings` (`progamming_name`, `progamming_details`) VALUES
('Angularjs', 'Angularjs Tutorials'),
('MySQL', 'MySQL Tutorials'),
('Vuejs', 'Vuejs Tutorials'),
('Laravel', 'Laravel Tutorials'),
('Javascript', 'Javascript Tutorials');

app/Progamming.php – Model Class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Progamming extends Model
{
    protected $fillable = [
        'progamming_name','progamming_details'
    ];
}

Step 2: Include Laravel Routes

routes/web.php

Route::get('progamming', '[email protected]');
Route::delete('progamming/{id}', ['as'=>'progamming.destroy','uses'=>'[email protected]']);
Route::delete('delete-multiple-progamming', ['as'=>'progamming.multiple-delete','uses'=>'[email protected]']);

Step 3: Make Progamming Laravel Controller

app/Http/Controllers/ProgammingController.php

Read Also:  Top 5 Mobile Apps To Get Free PayTm Cash & Free Mobile Recharge

We shall make a Laravel 5.6 controller “ProgammingController.php” in following path this app/Http/Controllers/.

delete();
        return back()->with('success','Progamming deleted successfully');
    }   

    public function deleteMultiple(Request $request){
        $ids = $request->ids;
        Progamming::whereIn('id',explode(",",$ids))->delete();
        return response()->json(['status'=>true,'message'=>"Progamming deleted successfully."]);
        
    }

}

Step 4: Make a Laravel View Blade File

resources/views/progammings.blade.php

progammings.blade.php



    <title>PHP Laravel 5.6 - How to delete multiple row with checkbox using Ajax?</title>

    
    
    
    
    





<div class="container">
    <h3>PHP Laravel 5.6 Delete Multiple Rows using Checkbox</h3>
    @if ($message = Session::get('success'))
    <div class="alert alert-success">
        <p>{{ $message }}</p>
    </div>
    @endif
    <button style="margin: 5px" class="pakainfo btn btn-danger btn-xs delete-all">Delete All</button>
    <table class="table table-bordered">
        <tr>
            <th></th>
            <th>S.No.</th>
            <th>Progamming Name</th>
            <th>Progamming Details</th>
            <th width="100px">Action</th>
        </tr>
        @if($progammings->count())
            @foreach($progammings as $key => $progamming)
                <tr>id}}">
                    <td>id}}"></td>
                    <td>{{ ++$key }}</td>
                    <td>{{ $progamming->progamming_name }}</td>
                    <td>{{ $progamming->progamming_details }}</td>
                    <td>
                        {!! Form::open(['method' => 'DELETE','route' => ['progamming.destroy', $progamming->id],'style'=>'display:inline']) !!}

                            {!! Form::button('Delete', ['class' => 'btn btn-danger btn-xs','data-toggle'=>'confirmation','data-placement'=>'left']) !!}

                        {!! Form::close() !!}
                    </td>
                </tr>
            @endforeach
        @endif
    </table>
</div> 




    $(document).ready(function () {

        $('#select_all').on('click', function(e) {
         if($(this).is(':checked',true))  
         {
            $(".checkbox").prop('checked', true);  
         } else {  
            $(".checkbox").prop('checked',false);  
         }  
        });

         $('.checkbox').on('click',function(){
            if($('.checkbox:checked').length == $('.checkbox').length){
                $('#select_all').prop('checked',true);
            }else{
                $('#select_all').prop('checked',false);
            }
         });

        $('.delete-all').on('click', function(e) {


            var allIds = [];  
            $(".checkbox:checked").each(function() {  
                allIds.push($(this).attr('data-id'));
            });  


            if(allIds.length <=0)  
            {  
                alert("Please select atleast one record to delete.");  
            }  else {  

                if(confirm("Are you sure, you want to delete the selected progammings?")){  

                    var strIds = allIds.join(","); 

                    $.ajax({
                        url: "{{ route('progamming.multiple-delete') }}",
                        type: 'DELETE',
                        headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                        data: 'ids='+strIds,
                        success: function (data) {
                            if (data['status']==true) {
                                $(".checkbox:checked").each(function() {  
                                    $(this).parents("tr").remove();
                                });
                                alert(data['message']);
                            } else {
                                alert('Sorry, Whoops Something went wrong!!');
                            }
                        },
                        error: function (data) {
                            alert(data.responseText);
                        }
                    });


                }  
            }  
        });

        $('[data-toggle=confirmation]').confirmation({
            rootSelector: '[data-toggle=confirmation]',
            onConfirm: function (event, element) {
                element.closest('form').submit();
            }
        });   
    
    });


Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Laravel Delete Multiple Checkboxes Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Laravel 5.6 Delete Multiple Rows using Checkbox.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.