After using AJAX to submit the data to be updated, I want to know what data is received in the controller. Is it the data in my table? Or is it the data for judgment?
## public function update(Request $request){
$status=0;
$id = $request->get ('id');
$data = $this->request->param();
// dump($data); What is the amount of data here? Let’s take a look. It doesn’t work with dump, and it can’t be executed?
$a=Db::name('dh')->where('id',$id)->update($data);
if (!$a ) {
$message = 'Failed to join. ';
} else {
$status = 1;
session('admin', $a); Join successfully! ';
} }
return ['status' => $status, 'message' => $message];
}
--------------------------------------------- -------------------------------------
$data is all the data of the form submitted by your front end through ajax. This is an associative array. tp5 uses json by default. Are you using dump output to verify the data in $data?
updata() Shouldn’t the sql statement of mysql be executed here? How can I execute $data directly?
$name= $this->request->param('name');
$add= $this->request->param('add');
$time= $this->request->param('update_time');
$a = Db::name('dh')
->where('id',$s)
- >data(['name' => $name,
'add'=>$add,
'update_time'=>$time
])
->update( );
Do you have to ask me to write like this? What if I have many fields to change?