Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

how to delete Multiple Selected rows using checkbox in laravel

how to delete Multiple Selected rows using checkbox in laravel

In this Post We Will Explain About is how to delete Multiple Selected rows using checkbox in laravel With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Laravel Delete multiple rows from mysql with checkbox Example

In this post we will show you Best way to implement Delete multiple records from MySQL in Laravel, hear for with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

how to delete multiple records using checkboxes in Laravel

Phase 1: Create items Table with fake Records

fake Records Query:Here, We Simple have to create all the “items” simple sql table then We can run mysql simple sql query for fake records. We can make items table using simple database like as a migration After that also make some fake records using like as a seeder. Therefor now We just simple run sql query.

  Laravel All Where eloquent methods with Examples

INSERT INTO `items` (`id`, `name`, `details`, `created_at`, `updated_at`) VALUES
(1, 'Laptop', 'Laptop posts', NULL, NULL),
(3, 'Mobile', 'Mobile posts', NULL, NULL),
(4, 'DVD', 'DVD posts', NULL, NULL),
(5, 'Computer', 'Computer posts', NULL, NULL),
(6, 'Tablet', 'Tablet posts', NULL, NULL);

Phase 2: Create new Routes

Route::get('myitems', '[email protected]');
Route::delete('myitems/{id}', '[email protected]');
Route::delete('myitemsDeleteAll', '[email protected]');

Phase 3: Add ItemController

app/Http/Controllers/ItemController.phpPlease put this source code in this path

get();
        return view('items',compact('items'));
    }

    public function destroy($id)
    {
    	DB::table("items")->delete($id);
    	return response()->json(['success'=>"Item Deleted successfully.", 'tr'=>'tr_'.$id]);
    }

    public function deleteAll(Request $request)
    {
        $item_ids = $request->item_ids;
        DB::table("items")->whereIn('id',explode(",",$item_ids))->delete();
        return response()->json(['success'=>"Items Deleted successfully."]);
    }
}

Phase 4: Add Blade File

resources/views/items.blade.php Please put this source code in this path



    <title>Laravel 5 step by step - Multiple some delete records using checkbox example</title>
    
    
    
    
    



<!-- Devloped by Pakainfo.com free download examples -->
<div class="container">
    <h3>Laravel 5 - steps Multiple delete all the records using checkbox example</h3>
    <button style="margin-bottom: 10px" class="btn btn-primary all_delete">Delete All Selected</button>
    <table class="table table-bordered">
        <tr>
            <th></th>
            <th>No</th>
            <th>Item Name</th>
            <th>Item Details</th>
            <th width="100px">Action</th>
        </tr>
        @if($items->count())
            @foreach($items as $key => $item)
                <tr>id}}">
                    <td>id}}"></td>
                    <td>{{ ++$key }}</td>
                    <td>{{ $item->name }}</td>
                    <td>{{ $item->details }}</td>
                    <td>
                         <a>id) }}" class="btn btn-danger btn-sm"
                           data-tr="tr_{{$item->id}}"
                           data-toggle="confirmation"
                           data-btn-ok-label="Delete" data-btn-ok-icon="fa fa-remove"
                           data-btn-ok-class="btn btn-sm btn-danger"
                           data-btn-cancel-label="Cancel"
                           data-btn-cancel-icon="fa fa-chevron-circle-left"
                           data-btn-cancel-class="btn btn-sm btn-success"
                           data-title="Please Confirm Are you sure you want to delete ?"
                           data-placement="left" data-singleton="true">
                            Delete
                        </a>
                    </td>
                </tr>
            @endforeach
        @endif
    </table>
</div> 


<!-- Devloped by Pakainfo.com free download examples -->

    $(document).ready(function () {

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

        $('.all_delete').on('click', function(e) {

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

            if(dataValues.length <=0)  
            {  
                console.log("Please some records select any row.");  
            }  else {  

                var check = confirm("Please Confirm Are We sure We want to delete this row?");  
                if(check == true){  

                    var join_selected_values = dataValues.join(","); 

                    $.ajax({
                        url: $(this).data('url'),
                        type: 'DELETE',
                        headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                        data: 'item_ids='+join_selected_values,
                        success: function (data) {
                            if (data['success']) {
                                $(".livesub_chk:checked").each(function() {  
                                    $(this).parents("tr").remove();
                                });
                                console.log(data['success']);
                            } else if (data['error']) {
                                console.log(data['error']);
                            } else {
                                console.log('Sorry Something went wrong!!');
                            }
                        },
                        error: function (data) {
                            console.log(data.responseText);
                        }
                    });

                  $.each(dataValues, function( index, value ) {
                      $('table tr').filter("[data-row-id='" + value + "']").remove();
                  });
                }  
            }  
        });

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

        $(document).on('confirm', function (e) {
            var ele = e.target;
            e.preventDefault();
			//call ajax
            $.ajax({
                url: ele.href,
                type: 'DELETE',
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                success: function (data) {
                    if (data['success']) {
                        $("#" + data['tr']).slideUp("slow");
                        console.log(data['success']);
                    } else if (data['error']) {
                        console.log(data['error']);
                    } else {
                        console.log('Sorry Something went wrong!!');
                    }
                },
                error: function (data) {
                    console.log(data.responseText);
                }
            });

            return false;
        });
    });

<!-- Devloped by Pakainfo.com free download examples -->

php artisan serve

And then last setp to you can open simple bellow url on your any browser:

  Remove HTML Table Row and Column using jQuery

http://localhost:8000/myitems

You are Most welcome in my youtube Channel Please shubscibe my channel. and give me FeedBackMore Details……
Angularjs Example

Example

I hope you have Got What is how to delete multiple rows using checkbox in php with Laravel And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.