In this video tutorial we will discuss how to update data in laravel query builder.Laravel edit and update method with hindi video explaination.
Controller method
In controller we define two type of methods first is edit() and other is update() method in edit method we define a from which contain default values that are already saved and editable.
and other is update method which perform update operation to store data.Here is over controller define where edit id=7 data.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class EmployeeController extends Controller{ public function edit(){ $id = 7; $employee = DB::table('employees')->find($id); return view('edit',compact('employee')); } public function update(Request $request){ $id = $request->id; $data = [ 'name' => $request->name, 'name' => $request->email, 'name' => $request->phone, ]; $update = DB::table('employees')->where('id', $id)->update($data); return redirect()->route('employee.edit'); } }
View file "edit.blade.php"
In edit view file make a form here is basic form without design.
<form method="post" action="{{ route('employee.update',$employee->id) }}"> @csrf <input type="text" name="name" value="{{ $employee->name }}"> <input type="email" name="email" value="{{ $employee->email }}"> <input type="text" name="phone" value="{{ $employee->phone }}"> <input type="submit" value="Update"> </form>
And these routes add in web.php
Route::get('employee/edit/{id}', [EmployeeController::, 'edit'])->name('employee.edit'); Route::post('employee/edit/{id}', [EmployeeController::, 'update'])->name('employee.update');
watch all query builder playlist click on sidebar playlist link
Anmol Sharma
I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.
Related tutorial links
- laravel query builder introduction tutorial
- part 1 laravel query insert data
- part 2 laravel all type of where conditions in query builder
- part 3 laravel whereDate, whereYear and whereTime qyery method
- part 4 compare two db columns in laravel query builder
- part 6 laravel pluck method get single column value
- part 7 laravel select and addselect query in query builder
- part 5 laravel first and find queries
- part 8 laravel edit and update method query explaination
- Part 9 laravel query for update or insert data by one method
- part 10 laravel delete vs truncate vs drop method
- part 11 gropupby and orderby query tutorial
- Part 12 laravel union of two queries
- part 13 laravel all aggregate functions with example
- part 14 laravel query builder chunk method
- part 15 laravel exists() and doesntExist() method
- part 16 laravel paginate vs simplePaginate method
- part 17 laravel all join methods