Php 在调用模型的方法时调用Laravel 4 BadMethodCallException

Php 在调用模型的方法时调用Laravel 4 BadMethodCallException,php,laravel-4,Php,Laravel 4,我在Laravel应用程序中创建了一个用户类,如下所示: <?php use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class User extends Eloquent implements UserInterface, RemindableInterface { ... public function hasAnyRoles() { return

我在Laravel应用程序中创建了一个用户类,如下所示:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {
...
public function hasAnyRoles()
{
     return true;
}
class WelcomeController extends Controller
{
  public function welcomeAction()
  {
     $user = User::find(Auth::user()->id);
     $result = $user->hasAnyRoles();
     return Response::make("Result: ".$result);
  }
}
我能够成功登录到系统,路由按预期工作,变量$user已正确初始化,我可以从中获取所有信息(用户名、id、电子邮件等),但一旦调用
$user->hasAnyRoles()
方法,我得到:

BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::hasAnyRoles()

如果我在控制器中注释掉相应的行,这一切都会起作用,但是我不能调用该模型的任何方法而不得到错误。你知道为什么会发生这种情况吗?

尽管很愚蠢,但事实证明应用程序是从另一个文件读取用户类的。为了以防万一,我在同一个目录中复制了一个User_backup.php,这是从中读取类的文件,因此对User.php的任何更改都被忽略。我必须删除备份文件并进行composer更新,以使其正常工作。

p.s.一旦解决问题,您可以将整个控制器压缩成一行代码
return Response::make(“结果:”.Auth::user()->hasAnyRoles())