2
我想用Laravel發送我的發送郵件的動作database
隊列 但是,這個過程仍然在我的瀏覽器中繼續,而不是在後面工作。Laravel 5.3隊列作業不起作用
這是我的控制器
protected function importUserExcel(UploadedFile $file, Request $request){
$user_role = Role::where('name','=','user')->first();
\Excel::load($file, function($reader) use ($user_role) {
$excel = $reader->select()->get();
foreach($excel[0] as $line){
$user = User::firstOrnew([
'email' => $line['email']]);
$user->email = $line['email'];
$user->name = $line['name'];
$user->password= bcrypt(srand(15));
$user->town = $line['town'];
$user->dealer_code = $line['dealer_code'];
$user->type = $line['type'];
// $user->save();
$user->sendUserEmail();
//$user->attachRole($user_role);
}
});
}
這是我的模型功能
public function sendUserEmail()
{
$delay = Carbon::now()->addMinutes(15);
\Log::info("Request Begins");
$user = new SendEmails($this);
$user->delay($delay);
dispatch($user);
\Log::info("Request Ends");
}
,這是我的工作
類SendEmails實現ShouldQueue { 使用InteractsWithQueue,QUEUEABLE,SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->handle($user);
}
/**
* Execute the job.
*
* @return void
*/
public function handle(User $user)
{
$broker = $user->broker;
$brokerInstance = \Password::broker($broker);
view()->share('locale', app()->getLocale());
$response = $brokerInstance->sendResetLink([ 'email' => $user->email ], function (Message $message) {
$message->subject(trans('emails.welcome_subject'));
});
}
}
然而結果似乎即將最終沒有延遲或排隊任何東西。同時我的瀏覽器也處理,而不是把流程放在後面。
您可以發佈完整的控制器功能嗎? –
ypdated @VũTuấnAnh –
你的代碼似乎很好,除了你的日誌。嘗試將您的日誌推送到'SendEmails'類。如果您將Logger推入模型中,則無法看到延遲時間。順便說一下,在你的控制器功能應該返回查看發送響應瀏覽器 –