有几种插入数据的方法:
public function run() { DB::table('users') ->insert([ 'name' => 'Taylor', 'age' => 21 ]); }
public function run() { $user = new User; $user->name = 'Taylor'; $user->save(); }
public function run() { User::create([ 'name' => 'Taylor', 'age' => 21 ]); }
public function run() { factory(App\User::class, 10)->create(); }
public function run() { DB::table('users')->delete(); DB::unprepared('ALTER TABLE users AUTO_INCREMENT=1;'); factory(App\User::class, 200)->create(); }
有关插入/更新数据的更多信息,请参见持久化示例。