where('created_at', '<', Carbon::now()->subDay(1)) ->with(['brand', 'customer']) ->get(); $customersLogins->map(function (CustomerLogin $customerLogin) { Log::info($customerLogin->customer_id); DB::transaction(function () use ($customerLogin) { /** @var \App\Models\Customer $customer */ $customer = $customerLogin->customer; /** @var \App\Models\Brand */ $brand = $customerLogin->brand; // * Suppression de ses infos de login pour la marque. $customer->info($brand, Customer::FIRST_OR_FAIL)->deleteOrFail(); $customer->login($brand, Customer::FIRST_OR_FAIL)->deleteOrFail(); // * Si le customer n'a plus d'info il n'a donc plus besoin de compte en crm. if (!$customer->infos()->count()) { // * Suppression du customer une fois tout le reste supprimé. $customer->optInHistory()->get() ->map(function (CustomerOptInHistory $customerOptInHistory) { $customerOptInHistory->deleteOrFail(); }); $customer->deleteOrFail(); } }); }); return 0; } }