laravel updateOrCreate的使用
//创建模型
php artisan make:model User
User.php
protected $table = 'table';//表名
protected $fillable=['fileds'];//允许更新的字段
public $timestamps = false;//不更新时间
UserController.php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
public function update(){
$where = [
'id' => 1,
]
$update_data = [
'id' => '2',
'name' => 'admin',
'password' => Hash::make('123456'),
]
//第一个是条件 ,第二个是更新或者创建的数据
$res = User::updateOrCreate($where,$update_data);
}
本作品采用《CC 协议》,转载必须注明作者和本文链接