When in Laravel 9 app logged user fill ContactUs form I need to send email to site support and show notification in app for any logged support member. I make it with notification and pusher In app/Notifications/ContactUsCreatedNotification.php :
<?php
namespace App\Notifications;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\User;
class ContactUsCreatedNotification extends Notification
{
public $title;
public $content_message;
public $authorUser;
public function __construct(string $title, string $content_message, User $authorUser)
{
$this->title = $title;
$this->content_message = $content_message;
$this->authorUser = $authorUser;
}
public function via($notifiable)
{
return ['mail', 'broadcast']; // I added broadcast here
}
public function toMail($notifiable)
{
return (new MailMessage)->markdown('mail.ContactUsCreatedNotification', [
'title' => $this->title,
'content_message' => $this->content_message,
'authorUser' => $this->authorUser
]);
}
public function toArray($notifiable)
{
return [
'title' => $this->title,
'content_message' => $this->content_message,
'authorUser' => $this->authorUser,
];
}
}
I got email on configured mailtrap but Debug console of my pusher app has no event : https://prnt.sc/L9nXEfup_3i-
in .env :
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
FILESYSTEM_DISK=local
SESSION_DRIVER=database
SESSION_LIFETIME=120
PUSHER_APP_ID=NNNN
PUSHER_APP_KEY=XXXXX
PUSHER_APP_SECRET=XXXXX
PUSHER_APP_CLUSTER=eu
In resources/js/bootstrap.js :
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
// alert('resources/js/bootstrap.js')
console.log('process.env.MIX_PUSHER_APP_KEY::')
console.log(process.env.MIX_PUSHER_APP_KEY)
console.log('process.env.MIX_PUSHER_APP_CLUSTER::')
console.log(process.env.MIX_PUSHER_APP_CLUSTER)
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
forceTLS: true
});
In the app I have
"laravel/framework": "^v9.6.0",
"predis/predis": "^1.1",
"pusher/pusher-php-server": "^7.0",
and
"laravel-echo": "^1.11.7",
Any ideas why notification event is not triggered ?
Thanks!
0 comments:
Post a Comment
Thanks