For getting every new tutorial link Please join our telegram group

Laravel edit and update method query builder tutorial with hindi video

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

php laravel developer anmol sharma

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