how to insert data using ajax in laravel with datatables?

Today, We want to share with you how to insert data using ajax in laravel with datatables?.In this post we will show you Insert Update and Delete record with AJAX in Laravel 6, hear for Laravel & Ajax – Insert data into table without refreshing we will give you demo and example for implement.In this post, we will learn about how to insert data using ajax in laravel with datatables with an example.

how to insert data using ajax in laravel with datatables?

There are the Following The simple About how to save data in database using ajax in laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 6 Inserting data to the database with Ajax , so the How to insert data using Laravel, Ajax is used for this example is following below.

Also Read This πŸ‘‰   Simple Angular Hello World Example

Step 1: Define a Laravel 6 Route



Step 2: Create a Controllers in Laravel

MemberInfoController.php (controller)

namespace App\Http\Controllers;

use App\MemberInfo;
use Illuminate\Http\Request;

class MemberInfoController extends Controller
public function create()
        return view('memberInformation.create');

public function store(Request $request)
            'name' => 'required',
            'email' => 'required',
        return json_encode(array(

Step 3: Create a Laravel Model

MemberInfo.php (Model)

namespace App;

use Illuminate\Database\Eloquent\Model;
class MemberInfo extends Model
    protected $table = 'members_details';
    protected $fillable = [
        'type','name', 'email','mobile','address'

Step 4: Create a Laravel Blade File


<div class="row">
    <div class="col-lg-12 margin-tb">
        <div class="pull-left">
            <h2>Add New Member</h2>
        <div class="pull-right">
            <a class="btn btn-primary" href="{{ route('memberInformation.index') }}"> Back</a>
@if ($errors->any())
    <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>

<div class="form-group cart-jdk">
        <input type="hidden" name="_token" id="csrf" value="{{Session::token()}}">
    <label for="email">Member First Name:</label>
    <input type="text" class="form-control custom-dsp" id="name" placeholder="Enter Member First Name" name="name">
  <div class="form-group cart-jdk">
    <label for="email">Email:</label>
    <input type="email" class="form-control custom-dsp" id="email" placeholder="Enter Email" name="email">
  <div class="form-group cart-jdk">
    <label for="email">Mobile:</label>
    <input type="text" class="form-control custom-dsp" id="mobile" placeholder="Enter Mobile" name="mobile">
  <div class="form-group cart-jdk">
    <label for="email">Address:</label>
    <input type="text" class="form-control custom-dsp" id="address" placeholder="Enter Address" name="address">
  <button type="submit" class="btn btn-primary" id="storememberbtn">Submit</button>
$(document).ready(function() {
    $('#storememberbtn').on('click', function() {
      var name = $('#name').val();
      var email = $('#email').val();
      var mobile = $('#mobile').val();
      var address = $('#address').val();
      var password = $('#password').val();
      if(name!="" && email!="" && mobile!="" && address!=""){
        //   $("#storememberbtn").attr("disabled", "disabled");
              url: "/memberInformation",
              type: "POST",
              data: {
                  _token: $("#csrf").val(),
                  type: 1,
                  name: name,
                  email: email,
                  mobile: mobile,
                  address: address
              cache: false,
              success: function(responseOutput){
                  var responseOutput = JSON.parse(responseOutput);
                    window.location = "/memberInformation";				
                  else if(responseOutput.statusCode==201){
                     alert("Error occured !");
          alert('Please fill all the field !');

Step 5: Main Master Layout Blade file


<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
    <title>PHP Laravel 6 CRUD using jQuery Ajax</title>
    <!-- Fonts -->
    <link href=",600" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src=""></script>
<div class="container">

Web Programming Tutorials Example with Demo

Read :

Also Read This πŸ‘‰   PHP File file_get_contents Handling Function


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

I hope you get an idea about add record using ajax laravel 6.
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.