1. Add
1.1 typical practice
User $ = new new the User; // Filter table column data non-post array, return the number of rows affected $ Data = only the Request :: ([ 'name', 'In Email' ]); $ User -> Save ( $ Data );
// Get the primary key
$ user-> id
User $ = new new the User; // POST array only name and email fields is written
// allowField used to specify the allowed field is true table field
$ User -> allowField ([ 'name', 'email']) -> the Save ( $ _POST );
1.2 Use the static method
$user = User::create([ 'name' => 'thinkphp', 'email' => '[email protected]' ]); echo $ User -> name; echo $ User -> In Email; echo $ User -> ID; // Get ID increment different and save methods are, create method returns the current instance of the object model.
//create
The second parameter can be passed to allow the method to write the list of fields (incoming true
said data field only allows writing the data table definition),
2 modified