【问题标题】:BadMethodCallException thrown with message "Call to undefined method Illuminate\Database\Query\Builder::raise()"BadMethodCallException 引发消息“调用未定义的方法 Illuminate\Database\Query\Builder::raise()”
【发布时间】:2015-04-14 08:28:25
【问题描述】:

我指的是 Larabook 关于 Laracasts 的第 16 课(出版状态)。 我安装了 Laravel 4.2 并且得到了一个

BadMethodCallException 抛出消息“调用未定义的方法 Illuminate\Database\Query\Builder::raise()”

存在方法“raise”的我的 Status.php 是:

<?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 中它也给了我一个错误

在静态类中找不到方法“raise”。

但导师 Jeffery Way 使用相同的方法,我无法弄清楚出了什么问题,因为其他用户在论坛中都没有遇到同样的错误。

【问题讨论】:

    标签: php laravel-4 phpmyadmin xampp eloquent


    【解决方案1】:
    • 您是否安装了“Laravel Commander”并为其更新了提供程序?
    • 您是否为事件 StatusWasPublished 制作了 CommandHandler?
    • 你必须添加命名空间use Laracasts\Commander\Events\EventGenerator;
    • 你需要在protected $fillable = ['body'];之前写use EventGenerator;

    Laravel Commander Package

    【讨论】:

    • 非常感谢!写作'使用EventGenerator;'成功了。
    猜你喜欢
    • 2016-04-10
    • 2019-12-12
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    相关资源
    最近更新 更多