Laravel Delete Multiple Checkboxes Example – Technology

Laravel Delete Multiple Checkboxes Example – Technology

In this post we will give you information about Laravel Delete Multiple Checkboxes Example – Technology. Hear we will give you detail about Laravel Delete Multiple Checkboxes Example – TechnologyAnd how to use it also give you demo for it if it is necessary.

Today, We want to share with you Laravel Delete Multiple Checkboxes Example.In this post we will show you Delete Multiple Data using Checkbox in Laravel 5.7, hear for How to delete multiple records using checkbox in Laravel 5.7 ? we will give you demo and example for implement.In this post, we will learn about PHP Laravel 5.7 – How to delete multiple row with checkbox using Ajax? with an example.

Laravel Delete Multiple Checkboxes Example

There are the Following The simple About Laravel Delete Multiple Checkboxes Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop php – Laravel delete multiple checkbox, so the some laravel multiple delete checkbox for this example is following below.

Another must read:  Simple AngularJS Shopping Cart Application

Phase 1: Create languages Table with Dummy Records

Dummy Mysql Records Query:

INSERT INTO 'languages' ('id', 'name', 'details', 'created_at', 'updated_at') VALUES
(1, 'AngularJS', 'AngularJS posts', NULL, NULL),
(3, 'Magento', 'Magento posts', NULL, NULL),
(4, 'VueJS', 'VueJS posts', NULL, NULL),
(5, 'CSS', 'CSS posts', NULL, NULL),
(6, 'Ajax', 'Ajax posts', NULL, NULL);

Phase 2: Make Laravel new Routes

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

routes/web.php

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

Route::delete('planguagesDeleteAll', '[email protected]');

Phase 3: Add programmmingController

app/Http/Controllers/programmmingController.php

<?php

namespace AppHttpControllers;
use IlluminateHttpRequest;
use DB;

class programmmingController extends Controller
{
    public function index()
    {
        $languages = DB::table("languages")->get();
        return view('languages',compact('languages'));
    }

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

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

Phase 4: Add Blade File

resources/views/languages.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Laravel 5 - Multiple delete records with checkbox example</title>
    <link rel="stylesheet" href="#">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7https://onlinecode.org/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-confirmation/1.0.5/bootstrap-confirmation.min.js"></script>
    <meta name="csrf-token" content="{{ csrf_token() }}">
</head>
<body>


<div >
    <h3>Laravel 5 - Multiple delete records with checkbox example</h3>
    <button style="margin-bottom: 10px"  data-url="{{ url('planguagesDeleteAll') }}">Delete All Selected</button>
    <table >
        <tr>
            <th width="50px"><input type="checkbox" id="programm"></th>
            <th width="80px">No</th>
            <th>Language Name</th>
            <th>Language Details</th>
            <th width="100px">Action</th>
        </tr>
        @if($languages->count())
            @foreach($languages as $key => $lang_item)
                <tr id="tr_{{$lang_item->id}}">
                    <td><input type="checkbox"  data-id="{{$lang_item->id}}"></td>
                    <td>{{ ++$key }}</td>
                    <td>{{ $lang_item->name }}</td>
                    <td>{{ $lang_item->details }}</td>
                    <td>
                         <a href="http://tridentsportscars.com/?big={{ url("planguages',$lang_item->id) }}" 
                           data-tr="tr_{{$lang_item->id}}"
                           data-toggle="confirmation"
                           data-btn-ok-label="Delete" data-btn-ok-icon="fa fa-remove"
                           data-btn-ok-
                           data-btn-cancel-label="Cancel"
                           data-btn-cancel-icon="fa fa-chevron-circle-left"
                           data-btn-cancel-
                           data-title="Are you sure you want to delete ?"
                           data-placement="left" data-singleton="true">
                            Delete
                        </a>
                    </td>
                </tr>
            @endforeach
        @endif
    </table>
</div>


</body>


<script type="text/javascript">
    $(document).ready(function () {


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

        $('.delete_all').on('click', function(e) {
            var listLangVal = [];  
            $(".lang_select:checked").each(function() {  
                listLangVal.push($(this).attr('data-id'));
            });  


            if(listLangVal.length <=0)  
            {  
                alert("Please select Any row.");  
            }  else {  

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

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


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


                  $.each(listLangVal, 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();

            $.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");
                        alert(data['success']);
                    } else if (data['error']) {
                        alert(data['error']);
                    } else {
                        alert('Sorry Something went wrong!!');
                    }
                },
                error: function (data) {
                    alert(data.responseText);
                }
            });


            return false;
        });
    });
</script>


</html>

url on your browser and run your Laravel Project

php artisan serve
http://localhost:8000/planguages
Angular 6 CRUD Operations Application Tutorials

Read :

Another must read:  Laravel Eloquent Relationships Join Multiple Tables

Summary

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

I hope you get an idea about Laravel Delete Multiple Checkboxes Example.
I would like to have feedback on my onlinecode 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.

Hope this code and post will helped you for implement Laravel Delete Multiple Checkboxes Example – Technology. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US