So, i'm trying to select a number of records if they don't already exist in another table. I have three models, Lead, SalesLog and Cron and the idea is to get all leads that are not already in the SalesLog and where the created_at field is greater than or equal to than the Crons duplicated_days field.
So far have something that looks like this, but it's not working at all
$leads = Lead::whereIn('status', [$minimumRequiredStatus])->whereNotIn('id', function($query) use ($cron) {
$query->table('sales_log')->select(['id'])->where('campaign', $cron->campaign);
})->get();
I can use filters for this but i might eventually be working with thousands and possibly millions of records on both the leads and sales_log tables.. This makes me apprehensive about doing it offline.
How could i run a query that would simply get all leads that are of the required status, not already inside of the sales_log and whose created_at field is equal to or greater than, say 30 days for instance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire