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.
Step 1: Define a Laravel 6 Route
web.php
Route::resource('/memberInformation','MemberInfoController');
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) { $request->validate([ 'name' => 'required', 'email' => 'required', ]); MemberInfo::create($request->all()); return json_encode(array( "statusCode"=>200 )); } }
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
create.blade.php
@extends('memberInformation.layout') @section('content')@if ($errors->any())Add New Member
Whoops! There were some problems with your input.@endif
@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach