我正在创建一个新应用程序,当文章被创建时,将显示一个通知。我已经尝试使用事件和侦听器。
我的App\Article.php
...
protected $events = [
'created' => Events\ArticleWasPublished::class
];
...
这是我的App\Providers\EventServiceProvider.php
文件
protected $listen = [
'App\Events\ArticleWasPublished' => [
'App\Listeners\NotifyUsers',
],
];
我的
App\Events\ArticleWasPublished.php
文件。...
use App\Article;
...
{
public $article;
public function __construct(Article $article)
{
$this->article = $article;
}
...
我的 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');
}
这里我做错了什么?
我的问题是当创建新文章时,没有创建新的通知。我甚至没有收到任何错误信息。