【发布时间】:2018-03-09 15:10:20
【问题描述】:
我在 laravel 上的通知有问题,如果我直接发送通知而不使用队列也可以
此通知需要发送电子邮件并保存在数据库中
我用这个来调用notify作为例子
$user = \App\User::find(1);
$candidato = \App\CandidatoVaga::where('id_user','=','1')->first();
$user->notify(new \App\Notifications\ConviteVagaCandidato($candidato));
这是\App\Notifications\ConviteVagaCandidato
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ConviteVagaCandidato extends Notification implements ShouldQueue
{
use Queueable;
protected $CandidatoVaga;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(\App\CandidatoVaga $CandidatoVaga)
{
$this->CandidatoVaga = $CandidatoVaga;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database','mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('Olá, '.$this->CandidatoVaga->user->DadosPessoais->nome)
->subject('Convite')
->markdown('email.convite_selecao');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'id_vaga' => $this->CandidatoVaga->id_vaga,
'id_user' => $this->CandidatoVaga->id_user,
'mensagem' => 'Você foi pré selecionado para a vaga',
'tipo' => 'Nova Vaga',
];
}
}
这会返回一个 sql 错误 SQLSTATE[42601]: Syntax error: 7 ERRO
但没有implements ShouldQueue 也可以
【问题讨论】:
-
什么是sql错误?
-
SQLSTATE[42601]:语法错误:7 错误:定界标识符在“””中或附近的大小为零第 1 行:... * 来自“candidatos_vaga”,其中“candidatos_vaga”。“”是null... ^ (SQL: select * from "candidatos_vaga" where "candidatos_vaga"."" is null limit 1)
-
尝试登录
$this->CandidatoVaga并在laravel.log中查看 -
我认为这是问题所在,我删除了所有 $this->CandidatoVaga 并开始工作,但我做错了什么?
-
可能模型没有正确加载模型,之前遇到过序列化问题。
标签: laravel laravel-5 queue laravel-5.5