I'm having trouble firing notifications with Laravel 5.4, I already followed the documentation steps, but I did not succeed.
Follow my code
\ LaraShop \ Users \ Notifications \ MessageUser
<?php namespace LaraShop\Users\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use LaraShop\Users\Emails\MailMessage as Mailable;
class MessageUser extends Notification
{
use Queueable;
private $message;
private $user;
public function __construct($message, $user)
{
//
$this->message = $message;
$this->user = $user;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new Mailable($this->message))->to($this->message->user->email);
}
public function toArray($notifiable)
{
return json_encode($this->message->toArray());
}
}
Class MailMessage
for E-mail firing.
\ LaraShop \ Users \ Emails \ MailMessage
<?php namespace LaraShop\Users\Emails;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use LaraShop\Users\Entities\Message;
class MailMessage extends Mailable
{
use Queueable, SerializesModels;
private $message;
public function __construct(Message $message)
{
$this->message = $message;
}
public function build()
{
return $this->view('emails.default', [
'email' => [
'title' => 'Hello World!',
'text' => 'Hello World!',
'button' => [
'label' => 'Acessar',
'url' => route('page.users.messages.index'),
]
]
]);
}
}
where I call Facade
of Notification
of Laravel
.
public function show(Request $request)
{
$message = Message::find($request->item);
\Notification::send($message, new MessageUser($message, $message->user));
return view('users::pages.messages.show', [
'message' => $message,
'user' => \Auth::user()
]);
}