Laravel中9个不经常用的小技巧汇总(2)

$posts = Post::withTrashed()->get();

查看仅被软删除的记录

$posts = Post::onlyTrashed()->get();

恢复软删除的模型

Post::withTrashed()->restore();

9. Eloquent时间方法

$posts = Post::whereDate('created_at', '2018-01-31')->get(); 
$posts = Post::whereMonth('created_at', '12')->get(); 
$posts = Post::whereDay('created_at', '31')->get(); 
$posts = Post::whereYear('created_at', date('Y'))->get(); 
$posts = Post::whereTime('created_at', '=', '14:13:58')->get();

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对黑区网络的支持。