I am trying to update my data in the database. but " edit " function just added new data, not updated. how can do that ?. thanks
public function index_update(){
$books = DB::select('select * from users');
return view('index2',['books'=>$books]);
}
public function show($id) {
$books = DB::select('select * from users where id = ?',[$id]);
return view('edit2',['books'=>$books]);
}
public function edit(Request $req,$id) {
$name = $req->input('name');
$email = $req->input('email') ;
$data=array('name'=>$name,'email'=>$email);
DB::table('users')->insert($data);
echo "data recorded successfully.";
}
-------------------
Route::get('/update','TestController@index_update')->name('display');
Route::get('edit/{id}','TestController@show')->name('updateD');
Route::post('/edit/{id}','TestController@edit')->name('updateEdit');;
-------------------
{!! csrf_field() !!}
Name
email
-----------**--------