I have this code below where i delete users on schedule,
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$users = User::onlyTrashed()->where(
'deleted_at', '<=', now()->subDays(1)->toDateTimeString()
)->get();
$users->each->forceDelete();
})->everyMinute(); // this is for test later changes to Daily
}
what i want to do
is to send email and inform them that their account has been deleted right before i delete their account which is $users->each->forceDelete();
so I added my setup email to my function like:
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$users = User::onlyTrashed()->where(
'deleted_at', '<=', now()->subDays(1)->toDateTimeString()
)->get();
$user = $users->each;
Mail::to($user->email)->send(new UserAutoDeleted($user));
$users->each->forceDelete();
})->everyMinute(); // this is for test later changes to Daily
}
and it keep gives me error such as:
SymfonyComponentDebugExceptionFatalThrowableError : Type error: Argument 1 passed to AppMailUserAutoDeleted::__construct() must be an instance of AppUser, instance of IlluminateSupportHigherOrderCollectionProxy given, called in C:laragonwwwmynewsiteappConsoleKernel.php on line 35
at C:laragonwwwmynewsiteappMailUserAutoDeleted.php: 21
17: * Create a new message instance.
18: *
19: * @return void
20: */
21: public function __construct(User $user)
22: {
23: $this->user = $user;
24: }
25:
26: /**
Exception trace:
1 AppMailUserAutoDeleted::__construct(Object(IlluminateSupportHigherOrderCollectionProxy))
C:laragonwwwmynewsiteappConsoleKernel.php : 35
2 AppConsoleKernel::AppConsole{closure}()
C:laragonwwwmynewsitevendorlaravelframeworksrcIlluminateContainerBoundMethod.php : 29
Please use the argument -v to see more details.
any idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…