PHP Laravel 6 SweetAlert jQuery Ajax Delete Rows Example

Today, We want to share with you PHP Laravel 6 SweetAlert jQuery Ajax Delete Rows Example.In this post we will show you Laravel 6 jQuery Ajax CRUD Example with Sweet Alert, hear for How to use sweet alert for delete confirm in Laravel 6? we will give you demo and example for implement.In this post, we will learn about Ajax SweetAlert for Live Data Deleting Rows in with PHP Laravel 6 with MySQL and jQuery with an example.

PHP Laravel 6 SweetAlert jQuery Ajax Delete Rows Example

There are the Following The simple About Laravel 6 Sweet Alert AJAX CRUD Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 6 confirmation box for delete a member from database example, so the Display Sweet Alert in Laravel 6 using uxweb/sweet-alert is used for this example is following below.

Phase 1: Download laravel

composer create-project --prefer-dist laravel/laravel aitsMGM

Phase 2: Create Database Migration

php artisan make:model School -m

Create a School model and schools table


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCompaniesTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('schools', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()


namespace App;

use Illuminate\Database\Eloquent\Model;

class School extends Model
    protected $fillable = [

Phase 3: Define routes


Route::get('/school', '[email protected]')->name('school.index');
Route::get('/schools', '[email protected]_school_data')->name('data');
Route::get('/addschool', '[email protected]')->name('school.view');
Route::post('/addschool', '[email protected]')->name('');
Route::delete('/addschool/{id}', '[email protected]')->name('school.destroy');
Route::get('/addschool/{id}/edit', '[email protected]')->name('school.update');

Phase 4: Create a Laravel 6 Controller

php artisan make:controller SchoolController


namespace App\Http\Controllers;

use App\School;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class SchoolController extends Controller
  public function view()
      return view('school.index');

  public function get_school_data(Request $request)
      $schools = School::latest()->paginate(5);

      return Request::ajax() ? 
                   : abort(404);

  public function Store(Request $request)
        'id' => $request->id
        'name' => $request->name,
        'locations' => $request->locations

    return response()->json(
        'success' => true,
        'message' => 'Data inserted successfully'

  public function update($id)
    $comapny  = School::find($id);

    return response()->json([
      'data' => $comapny
  public function destroy($id)
    $school = School::find($id);


    return response()->json([
      'message' => 'Data deleted successfully!'


Phase 5: Create View File


Also Read This ๐Ÿ‘‰   PHP Web Application create Installer scripts

<!doctype html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>PHP Laravel 6 ajax crud - infinityknow </title>

    <script src="{{ asset('js/app.js') }}" defer></script>
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">

        <main class="py-4">

        var root_url = <?php echo json_encode(route('data')) ?>;
        var store = <?php echo json_encode(route('')) ?>;




<div class="container">
   <div class="row justify-content-center">
      <div class="col-md-8">
          <div class="card">
            <a href="javascript:void(0)" class="btn btn-sm btn-outline-danger py-0" style="font-size: 0.8em; width:100px;" id="createNewSchool">Add School</a>
            <table class="table table-bordered">
                     <th width="200px">Action</th>




<script src=""></script>  
<script src="[email protected]"></script>

<script src="/js/ajax.js"></script>



<div class="modal fade" id="student-id">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="studentCrudModal"></h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

            <div class="modal-body">
                <form id="schooldata">

                    <input type="hidden" id="school_id" name="school_id" value="">
                    <input type="text" id="name" name="name" value="">
                    <input type="text" id="locations" name="locations" value="">

                    <input type="submit" value="Submit" id="submit" class="btn btn-sm btn-outline-danger py-0" style="font-size: 0.8em;">




$(document).ready(function () {

    headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

//Get all school
function get_school_data() {
        url: root_url,
    	data: { }

//School table row
function table_data_row(data) {

    var	rows = '';
	$.each( data, function( key, value ) {
	  	rows = rows + '<tr>';
	  	rows = rows + '<td>''</td>';
	  	rows = rows + '<td>'+value.locations+'</td>';
	  	rows = rows + '<td data-id="''">';
                rows = rows + '<a class="btn btn-sm btn-outline-danger py-0" style="font-size: 0.8em;" id="editSchool" data-id="''" data-toggle="modal" data-target="#student-id" rel="noopener noreferrer">Edit</a> ';
                rows = rows + '<a class="btn btn-sm btn-outline-danger py-0" style="font-size: 0.8em;" id="deleteSchool" data-id="''" >Delete</a> ';
                rows = rows + '</td>';
	  	rows = rows + '</tr>';


//Insert school data

    $('#studentCrudModal').html("Create school");
    $('#submit').val("Create school");


//Save data into database
$('body').on('click', '#submit', function (event) {
    var id = $("#school_id").val();
    var name = $("#name").val();
    var locations = $("#locations").val();
      url: store,
      type: "POST",
      data: {
        id: id,
        name: name,
        locations: locations
      dataType: 'json',
      success: function (data) {
            position: 'top-end',
            icon: 'success',
            title: 'Success',
            showConfirmButton: false,
            timer: 1500
      error: function (data) {

//Edit modal window
$('body').on('click', '#editSchool', function (event) {

    var id = $(this).data('id');
    $.get(store+'/'+ id+'/edit', function (data) {
         $('#studentCrudModal').html("Edit school");
         $('#submit').val("Edit school");

 $('body').on('click', '#deleteSchool', function (event) {
    if(!confirm("Do you really want to do this?")) {
       return false;

    var id = $(this).attr('data-id');
          url: store+'/'+id,
          type: 'DELETE',
          data: {
                id: id
        success: function (response){
              'School deleted successfully!',
      return false;


Web Programming Tutorials Example with Demo

Read :

Also Read This ๐Ÿ‘‰   Laravel 6 left join query Example Tutorial


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

I hope you get an idea about sweet alert php response.
I would like to have feedback on my 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.