Laravel 模型的自定义方法 BadMethodCallException - 尝试使用 workbench 文件夹的供应商文件?

Laravel model's custom method BadMethodCallException - tries to use workbench folder's vendor files?

我经常在模型文件中添加自定义方法时遇到奇怪的错误。从路由文件中我查询了模型但得到了 "method not found" – 从错误日志中显示 Laravel 正在使用 workbench 文件夹下的供应商文件,即使 workbench 包不是以任何方式与此代码相关。

Route::get('/test', function () {
    $obj = MyModel::where('id', 1111)->get()->first();
    return $obj->toCustomFormat();
});


[2015-02-03 16:08:08] development.ERROR: exception 'BadMethodCallException' with message 'Call to undefined method Illuminate\Database\Query\Builder::toCustomFormat()' in /var/www/project/workbench/envision/mypackage/vendor/illuminate/database/Illuminate/Database/Query/Builder.php:2117
Stack trace:
#0 [internal function]: Illuminate\Database\Query\Builder->__call('toCustomForm...', Array)
#1 [internal function]: Illuminate\Database\Query\Builder->toCustomFormat()
#2 /var/www/project/workbench/envision/mypackage/vendor/illuminate/database/Illuminate/Database/Eloquent/Builder.php(913): call_user_func_array(Array, Array)
#3 [internal function]: Illuminate\Database\Eloquent\Builder->__call('toCustomForm...', Array)
#4 [internal function]: Illuminate\Database\Eloquent\Builder->toCustomFormat()
#5 /var/www/project/bootstrap/compiled.php(7459): call_user_func_array(Array, Array)
#6 /var/www/project/app/routes.php(12): Illuminate\Database\Eloquent\Model->__call('toCustomForm...', Array)
#7 /var/www/project/app/routes.php(12): MyModel->toCustomFormat()
#8 [internal function]: {closure}()

artisan 在项目根目录下转储没有帮助。你是怎么做到的?

更新:

模型的自定义方法是这样的:

public function toCustomFormat() {
    $this->to       = date(DateTime::ISO8601, strtotime($this->to));
    $this->from     = date(DateTime::ISO8601, strtotime($this->from));
    return $this->toArray();
}

问题是混淆了通过 FTP 保存文件。所以该方法不在模型的文件中。

然而,看到 Laravel 试图在 workbench 的文件夹中的包下找到该方法是一种误导,该文件夹有另一个供应商文件夹。也许 Laravel 在模型文件夹中找不到丢失的方法时,尝试升级搜索该位置下丢失的方法。