//Command
class SendDailyNewsletterCommand extends Command {
//...
$subscriptions->each(function ($subscription) {
SendDailyNewsletter::dispatch($subscription->email)->delay(10);
});
}
// Job
class SendDailyNewsletter implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $email;
public function __construct($email)
{
$this->email = $email;
}
public function handle()
{
Redis::throttle('key')->allow(1)->every(5)->then(function () {
// send email to subscriber
logger($this->email);
}, function () {
// could not obtain lock, retry this job in 5 seconds.
return $this->release(5);
});
}
}
// Лог файл
//[2019-06-25 09:13:11] local: sdfsdf@korwru.ru
//[2019-06-25 09:13:16] local: gusin.matvei@example.net
//[2019-06-25 09:13:21] local: subbotin.elvira@example.com
//[2019-06-25 09:13:26] local: faina92@example.org
//[2019-06-25 09:13:31] local: lidiy04@example.com
//[2019-06-25 09:13:36] local: sdfsdf@wolq.net
//[2019-06-25 09:13:41] local: polina51@example.net
class CreateRequest extends FormRequest
{
//..
public function rules(): array
{
return [
'expires_at' => 'required|date',
];
}
public function messages()
{
return [
//'expires_at.required' =>'Обязательно заполните! Иначе сайт не работает :)',
'expires_at.required' => trans('global.user.zzz'), //Ссылаемся на значение поля user['zzz'] из файла resources/lang/ru/global.php
];
}
}
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.ru
MAIL_PORT=587
MAIL_USERNAME=noreply@vacanc.ru
MAIL_PASSWORD=ПАРОЛЬ
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@vacanc.ru
MAIL_FROM_NAME=Vacanc
php artisan config:cache
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.ru
MAIL_PORT=587
MAIL_USERNAME=noreply@vacanc.ru
MAIL_PASSWORD=ПАРОЛЬ
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@vacanc.ru
MAIL_FROM_NAME=Vacanc
php artisan config:cache
MAIL_DRIVER=smtp
MAIL_HOST=smtp.yandex.ru
MAIL_PORT=587
MAIL_USERNAME=noreply@vacanc.ru
MAIL_PASSWORD=ПАРОЛЬ
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@vacanc.ru
MAIL_FROM_NAME=Vacanc
php artisan config:cache