Today, We want to share with you laravel ajax crud.In this post we will show you Ajax CRUD [CReate Update Delete] with PHP Laravel and MySQL database, hear for laravel c.r.u.d. with modals & ajax we will give you demo and example for implement.In this post, we will learn about PHP Laravel MySQL CRUD Application with an example.
CRUD application in Laravel using jQuery
Add, Edit, Update, and Delete functionality is used almost every PHP Laravel application.
Install Yajra Datatable
composer require yajra/laravel-datatables-oracle
config/app.php
..... 'providers' => [ .... Yajra\DataTables\DataTablesServiceProvider::class, ] 'aliases' => [ .... 'DataTables' => Yajra\DataTables\Facades\DataTables::class, ] .....
Step 3: Database Configuration
.env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=here your database name(blog) DB_USERNAME=here database username(root) DB_PASSWORD=here database password(root)
Step 4: Create Migration Table
php artisan make:migration create_brands_table --create=brands
bigIncrements('id'); $table->string('name'); $table->text('information'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('brands'); } }
Step 5: Create Route
routes/web.php
Route::resource('ajaxbrands','BrandAjaxController');
Add Controller and Model
app/Http/Controllers/BrandAjaxController.php
ajax()) { $data = Brand::latest()->get(); return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ $btn = 'Edit'; $btn = $btn.' Delete'; return $btn; }) ->rawColumns(['action']) ->make(true); } return view('brandAjax',compact('brands')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { Brand::updateOrCreate(['id' => $request->brand_id], ['name' => $request->name, 'information' => $request->information]); return response()->json(['success'=>'Brand saved successfully.']); } /** * Show the form for editing the specified resource. * * @param \App\Brand $brand * @return \Illuminate\Http\Response */ public function edit($id) { $brand = Brand::find($id); return response()->json($brand); } /** * Remove the specified resource from storage. * * @param \App\Brand $brand * @return \Illuminate\Http\Response */ public function destroy($id) { Brand::find($id)->delete(); return response()->json(['success'=>'Brand deleted successfully.']); } }
app/Brand.php
Step 7: Add Blade Files
resources/views/brandAjax.blade.php
Laravel 6 Ajax CRUD tutorial using Datatable - Pakainfo.com I hope you get an idea about CRUD stands for Create, Read, Update and Delete database data..
I would like to have feedback on my infinityknow.com 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.