2
我如何使用這樣的代碼:如何使用firstOrCreate一凡在Laravel 5.4
$db = ModelName::firstOrCreate(['bot_id'=>10, 'bot_text'=>$botTxt->id])
->where('updated_at','<=', Carbon::today());
這不能正常工作。
我如何使用這樣的代碼:如何使用firstOrCreate一凡在Laravel 5.4
$db = ModelName::firstOrCreate(['bot_id'=>10, 'bot_text'=>$botTxt->id])
->where('updated_at','<=', Carbon::today());
這不能正常工作。
正確的語法是:
ModelName::where('updated_at','<=', Carbon::today())
->firstOrCreate(['bot_id' => 10, 'bot_text' => $botTxt->id]);
而且,由於firstOrCreate()
使用質量分配功能,請確保你定義在ModelName
類$fillable
屬性:
protected $fillable = ['bot_id', 'bot_text'];
我什麼固定不工作,你可以檢查'dd($ db);'每次'+ exists:true' !!!!例如,當我每次將mySql數據中的'updated_at'更改爲'2017-07-28 18:03:49'或'2017-07-25 18:03:49'時 –