1
I’m having trouble firing notifications with Laravel 5.4, I’ve already followed the steps of the documentation, but was unsuccessful.
Follows 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
to trigger the e-mail.
\Larashop Users Mailmessage Emails
<?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 the 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()
]);
}
What’s the matter!?
– novic
Does not send the E-mail and also not saved in the bank the notification.
– Raank
The way you’re doing is just sending an e-mail.
– novic