Php 将身份验证用户数据传递到队列作业类
我创建了一个在后台处理PDF的作业。我想火了一封电子邮件给Auth用户一旦工作完成与一个链接下载新生成的PDF 以下是我目前正在做的事情 控制器:Php 将身份验证用户数据传递到队列作业类,php,laravel,jobs,Php,Laravel,Jobs,我创建了一个在后台处理PDF的作业。我想火了一封电子邮件给Auth用户一旦工作完成与一个链接下载新生成的PDF 以下是我目前正在做的事情 控制器: public function haitiKidPdfAll(){ $pdfUser = User::find(Auth::user()->id); $haitiKids = Kid:: whereRaw('sponsors_received < sp
public function haitiKidPdfAll(){
$pdfUser = User::find(Auth::user()->id);
$haitiKids = Kid::
whereRaw('sponsors_received < sponsors_needed')
->where('current_country', 'Haiti')
->orderBy('sponsors_received', 'ASC')
->get();
ProcessPdfHaiti::dispatch($haitiKids,$pdfUser);
return back()->with('info','This will take a couple minutes. I\'ll email you when it\'s completed.');
class PdfFinished extends Mailable
{
use Queueable, SerializesModels;
public $pdfUserName;
public $pdfpath;
public function __construct($pdfUserName,$pdfpath)
{
$this->pdfUserName =$pdfUserName;
$this->pdfpath =$pdfpath;
}
public function build()
{
return $this->subject('PDF Has Completed')->markdown('emails.staff.pdfcompleted');
}
}
@component('mail::message')
### Hello {{ $pdfUserName }},<br>
..etc
@endcomponent
可邮寄:
public function haitiKidPdfAll(){
$pdfUser = User::find(Auth::user()->id);
$haitiKids = Kid::
whereRaw('sponsors_received < sponsors_needed')
->where('current_country', 'Haiti')
->orderBy('sponsors_received', 'ASC')
->get();
ProcessPdfHaiti::dispatch($haitiKids,$pdfUser);
return back()->with('info','This will take a couple minutes. I\'ll email you when it\'s completed.');
class PdfFinished extends Mailable
{
use Queueable, SerializesModels;
public $pdfUserName;
public $pdfpath;
public function __construct($pdfUserName,$pdfpath)
{
$this->pdfUserName =$pdfUserName;
$this->pdfpath =$pdfpath;
}
public function build()
{
return $this->subject('PDF Has Completed')->markdown('emails.staff.pdfcompleted');
}
}
@component('mail::message')
### Hello {{ $pdfUserName }},<br>
..etc
@endcomponent
发送给身份验证用户的电子邮件:
public function haitiKidPdfAll(){
$pdfUser = User::find(Auth::user()->id);
$haitiKids = Kid::
whereRaw('sponsors_received < sponsors_needed')
->where('current_country', 'Haiti')
->orderBy('sponsors_received', 'ASC')
->get();
ProcessPdfHaiti::dispatch($haitiKids,$pdfUser);
return back()->with('info','This will take a couple minutes. I\'ll email you when it\'s completed.');
class PdfFinished extends Mailable
{
use Queueable, SerializesModels;
public $pdfUserName;
public $pdfpath;
public function __construct($pdfUserName,$pdfpath)
{
$this->pdfUserName =$pdfUserName;
$this->pdfpath =$pdfpath;
}
public function build()
{
return $this->subject('PDF Has Completed')->markdown('emails.staff.pdfcompleted');
}
}
@component('mail::message')
### Hello {{ $pdfUserName }},<br>
..etc
@endcomponent
@组件('mail::message')
###你好{{$pdfUserName},
等
@端部元件
我已经做了好几天了。任何帮助都将不胜感激。您需要使用
$this
关键字来访问它们,因为您已经在您的工作中对它们进行了初始化
$pdfUserEmail = $this->pdfUser->email;
$pdfUserName = $this->pdfUser->first_name;
另外,Auth::user()
返回App\user的实例,因此您不需要执行user::find
,因为您已经有了一个用户模型。所以你可以这样称呼你的工作:
ProcessPdfHaiti::dispatch($haitiKids,Auth::user())代码>
希望有帮助:)效果很好。就我而言,这是一个简单的疏忽。谢谢你的帮助@不用担心,一切都在那里!还添加了一些关于使用Auth::user()的额外信息,您可能会发现这些信息很有用!所以,如果我像你说的那样使用ProcessPdfHaiti::dispatch($haitiKids,Auth::user())代码>如何传递$pdfUser=User::find(Auth::User()->id)代码>从控制器到作业。我仍然需要通过$pdfUser
。。正确吗?@echo您不需要创建变量$pdfUser
,因为它与Auth::user()
完全相同-您只使用一次,因此无需将其分配给变量。您可以将其作为Auth::user()
传入,构造函数会将其转换为作业类中的$this->pdfUser
,但也可以执行$pdfUser=Auth::user()代码>并将其传递到您的工作中,就像这样ProcessPdfHaiti::dispatch($haitiKids,$pdfUser)代码>