BadMethodCallException 抛出消息 "Call to undefined method Illuminate\Database\Query\Builder::raise()"
BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::raise()"
我指的是关于 Laracasts 的 Larabook 第 16 课(发布状态)。
我安装了 Laravel 4.2 并且得到了
BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::raise()"
我的 Status.php 方法 'raise' 是:
<?php
namespace SocialBucket\Statuses;
use SocialBucket\Statuses\Events\StatusWasPublished;
class Status extends \Eloquent {
/*
* fillable fields for a new status.
*/
protected $fillable = ['body'];
/*
* A status belongs to a user.
*/
public function user()
{
return $this->belongsTo('SocialBucket\Users\User');
}
/**
* Publish a new status.
* @param $body
* @return static
*/
public static function publish($body)
{
$status = new static(compact('body'));
$status->raise(new StatusWasPublished($body));
return $status;
}
}
在 PHPStorm 中它也给我一个错误
Method 'raise' not found in class static.
但是 Jeffery Way 讲师使用相同的方法,我无法弄清楚哪里出了问题,因为 none 的其他用户在论坛中遇到了同样的错误。
- 您是否安装了 'Laravel Commander' 并为其更新了 Provider?
- 您是否为事件 StatusWasPublished 创建了 CommandHandler?
- 您必须添加命名空间
use Laracasts\Commander\Events\EventGenerator;
- 你需要在
protected $fillable = ['body'];
之前写上use EventGenerator;
我指的是关于 Laracasts 的 Larabook 第 16 课(发布状态)。 我安装了 Laravel 4.2 并且得到了
BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::raise()"
我的 Status.php 方法 'raise' 是:
<?php
namespace SocialBucket\Statuses;
use SocialBucket\Statuses\Events\StatusWasPublished;
class Status extends \Eloquent {
/*
* fillable fields for a new status.
*/
protected $fillable = ['body'];
/*
* A status belongs to a user.
*/
public function user()
{
return $this->belongsTo('SocialBucket\Users\User');
}
/**
* Publish a new status.
* @param $body
* @return static
*/
public static function publish($body)
{
$status = new static(compact('body'));
$status->raise(new StatusWasPublished($body));
return $status;
}
}
在 PHPStorm 中它也给我一个错误
Method 'raise' not found in class static.
但是 Jeffery Way 讲师使用相同的方法,我无法弄清楚哪里出了问题,因为 none 的其他用户在论坛中遇到了同样的错误。
- 您是否安装了 'Laravel Commander' 并为其更新了 Provider?
- 您是否为事件 StatusWasPublished 创建了 CommandHandler?
- 您必须添加命名空间
use Laracasts\Commander\Events\EventGenerator;
- 你需要在
protected $fillable = ['body'];
之前写上
use EventGenerator;