I am creating a new Application on which when a article is created a notification will be show. I have tried using events and listeners.
My App\Article.php
...
protected $events = [
'created' => Events\ArticleWasPublished::class
];
...
My App\Providers\EventServiceProvider.php
protected $listen = [
'App\Events\ArticleWasPublished' => [
'App\Listeners\NotifyUsers',
],
];
My App\Events\ArticleWasPublished.php
...
use App\Article;
...
{
public $article;
public function __construct(Article $article)
{
$this->article = $article;
}
...
My App\Listeners\NotifyUsers.php
use App\Notification;
...
public function handle(ArticleWasPublished $event)
{
Notification::create([
'article_id' => $event->article->id,
'message' => 'A new Article was created'
]);
var_dump('Something');
}
What am I doing wrong here?
My problem is when a new article is created a new notification is not getting created. I am not even getting any errors.