Laravel: Filter out users created more than three months ago
P粉115840076
P粉115840076 2023-08-27 23:01:14
0
1
404
<p>In my Laravel application, I want to get all user records where the "created_at" timestamp is three months earlier than the current date. Is this possible using the Eloquent query builder? </p>
P粉115840076
P粉115840076

reply all(1)
P粉146080556

First, you can use Carbon to get the date 3 months ago.

$date = Carbon::now()->subMonths(3)->format('Y-m-d');

Then we need all the records before that. So, the query should be -

$users = User::where('created_at', '<=', $date)->get();
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!