我有一个带有“ created_at”属性的Laravel集合,我想按年份进行过滤,就像雄辩的那样:
<div class="white-container">
<div class="container">
<div>
<ul class="firstthree">
<li>
<img src="images/brush.svg" class="brush" alt="brush">
<p class="brush">Graphic Design</p>
</li>
<li>
<img src="images/wand.svg" class="wand" alt="wand">
<p class="wand">UI Design</p>
</li>
<li>
<img src="images/code.svg" class="code2" alt="code">
<p class="code">Front-end Dev</p>
</li>
</ul>
</div>
<div>
<ul class="secondthree">
<li>
<img src="images/settings.svg" class="settings" alt="settings">
<p class="settings">Back-end Dev</p>
</li>
<li>
<img src="images/database.svg" class="database" alt="databases">
<p class = "database">Databases</p>
</li>
<li>
<img src="images/mobile.svg" class="mobile" alt="mobile">
<p class="mobile">Mobile Devices</p>
</li>
</ul>
</div>
</div>
</div>
但是在一个集合中。
谢谢!
$model->whereYear()
答案 0 :(得分:1)
您可以使用“收藏夹”方法filter来查找年份符合您的条件的那些人:
$collection = Model::all();
$collection->filter(function ($value) {
return $value->created_at->year === 2019; // assuming, that your timestamp gets converted to a Carbon object.
});