Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kikter's avatar

get column count in in last 7days

so i want to get column count for the past 7days please how can i do this

$date = \Carbon\Carbon::today()->subDays(7);
$ads = Ads::where('clone_ad')->where('created_at','>=',$date)->get();
0 likes
3 replies
tykus's avatar
$ads = Ad::whereDate('created_at', '>=', today()->subDays(7))->count();

What is the where('clone_ad') constraint supposed to be doing?

kikter's avatar

@tykus in my ads table I have clone_ad I would like to get the count of that column

tykus's avatar
tykus
Best Answer
Level 104

@kikter is clone_ad an INT type you want to total?

$ads = Ad::query()
    ->whereDate('created_at', '>=', today()->subDays(7))
    ->sum('clone_ad');

Or do you want a count of the rows where clone_ad has a particular value?

$ads = Ad::query()
    ->where('clone_ad', /* some value */)
    ->whereDate('created_at', '>=', today()->subDays(7))
    ->count();

Please or to participate in this conversation.