关于 Laravel 的事件 Event 的的一个简单的问题

我按照教程学习laravel的事件,但是老是报这个错误Call to undefined method Illuminate\Events\Dispatcher::fire()
我在EventServiceProvider 里面想添加一个事件,
protected $listen = [
'App\Events\NewBlogView' => [
'App\Listeners\NewBlogViewListener',
],
]
然后在NewBlogView.php文件中,用了一个模型获取用户,
public $users;
public function __construct(User $user)
{
$this->users=$user;
}

然后在NewBlogViewListener.php中,handle方法
public function handle(NewBlogView $event)
{
$id = $event->users->id;
return $id.'news';
}
添加一条路由,
Route::get('/event/{id}','BlogController@showPost');
在控制器中 BlogController.php ,
use Event;
public function showPost($id)
{
$user = User::find($id);
Event::fire(new NewBlogView($user));
}
我都是按照教程写的,但是就老是报错,帮忙看看哪里出了问题,这Event门面有没有这个fire方法的?

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 4

当我用event(new NewBlogView($user)); 运行不报错,用大写的Event时候就报错

4年前 评论

大写的是 这样写 \EVENT

3年前 评论

Event::dispatch(new OrderEvent($article_result));

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!