// filter non-data table fields update public = model ( " user " = $user, Allowfield (true )->save ($request->param (), [ Span style= "COLOR: #800000" > " id " = >1 ]); Dump ($result); // The number of rows affected }
// update the specified field Public = model (" user " ); $result = $user Allowfield ([ " name ", " Email "])->save ($request->param (), [ " id " =>9 ]) ; Dump ($result); }
Database class update data (recommended)
Public function Update (Request $request) { = model ('User'); $user,where('ID',1) ->update ( ['name'='chrdai']); }
Closure Update data (recommended when update conditions are multiple)
Public function $request { $user = Model (' user '); $user->save ([' name ' = ' Chrdai '],function($query) { $ Query->where (' status ', 1)->where (' id ', ' > '); });
static method Update Data
Publicfunction Update (Request $request) {$user= Model ('User'); $user::where('ID',1) ->update (['name'='Chrdai','Email'='[email protected]']); }
Batch update Data SaveAll ()
$user =model ('User'); $list= [ ['ID'=1,'name'='thinkphp','Email'='[email protected]'], ['ID'=2,'name'='Onethink','Email'='[email protected]']]; $user->saveall ($list);
Update method of model in TP5