duanli3277 2017-07-28 17:46
浏览 289
已采纳

如何在Laravel 5.4中使用firstOrCreate中的where

How can I use a code like this:

 $db = ModelName::firstOrCreate(['bot_id'=>10, 'bot_text'=>$botTxt->id])
->where('updated_at','<=', Carbon::today());

This is not working correctly.

  • 写回答

1条回答 默认 最新

  • dousuochu7291 2017-07-28 17:47
    关注

    The correct syntax is:

    ModelName::where('updated_at','<=', Carbon::today())
        ->firstOrCreate(['bot_id' => 10, 'bot_text' => $botTxt->id]);
    

    Also, since firstOrCreate() uses the mass assignment feature, make sure you've defined the $fillable property in the ModelName class:

    protected $fillable = ['bot_id', 'bot_text'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?