Support the ongoing development of Laravel.io →
Database Queues Installation

So I'm checking to see that a "tag" has expired 7 days ago. But I also want to make sure that there aren't any other tags that are still valid within the same query. So, if there are other tags connected to the user that the tag is "active = 1" AND expiry_date is still in the future (tomorrow, at least), ignore that users tags altogether.

I've got the first part working fine:

$seven_days_ago_start = date('Y-m-d', strtotime('-7 days')) . ' 00:00:01';
$seven_days_ago_end = date('Y-m-d', strtotime('-7 days')) . ' 23:59:59';

$expired_tags = DB::table('tags')
        ->leftJoin('users', 'tags.user_id', '=', 'users.id')
        ->leftJoin('pets', 'pets.id', '=', 'tags.pet_id')
        ->where('tags.active', '=', 1)
        ->whereBetween('tags.expiry_date', array($seven_days_ago_start, $seven_days_ago_end))
        ->select('users.id', 'users.username', 'users.email', 'users.first_name', 'tags.serial_number')
        ->get();
Last updated 2 years ago.
0

I hoping someone is able to help me out with this... I really don't know the best way to construct this query.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

dcolumbus dcolumbus Joined 29 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.