我有选择所有文章的代码。我认为我在做的是错误的。我选择所有值,然后执行它们。
Article::all()->each(function($article) {
if ($article->created_at == $article->published_at && $article>published) {
$article->update(['published_at' => null]);
}
});
我需要做的是仅选择具有相同的created_at和updated_at的文章。
如何在数据库级别执行此操作?我需要这样的东西:
Article::where('created_at', '=', 'published_at')->where('published')->get()->each(function($article) {
$article->update(['published_at' => null]);
}
});
这段代码肯定行不通,仅是想而知。
您只需要在两列上搜索一个值:
Article::where(['created_at' => $date, 'updated_at' => $date ])->get();
编辑:
为此使用whereRaw
Article::whereRaw('created_at = updated_at')->get();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句