2014-11-09 62 views
0

位于User模型中的所有Laravel模型函数都拒绝工作。他们都返回Call to undefined method Illuminate\Database\Query\Builder::foo()。如果我在另一个模型中创建一个函数,关系和一切工作。我不确定我做错了什么。这是我的整个User.php文件。Laravel用户模型

<?php 

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

class User extends Eloquent implements UserInterface, RemindableInterface { 

    public function seminar() 
    { 
     return $this->hasMany('Seminar'); 
    } 

    use UserTrait, RemindableTrait; 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'users'; 

    /** 
    * The attributes excluded from the model's JSON form. 
    * 
    * @var array 
    */ 
    protected $hidden = array('password', 'remember_token'); 

} 

这里是在同一个项目

<?php 

class Seminar extends Eloquent { 

    protected $table = 'seminar'; 


    public function user() 
    { 
     return $this->belongsTo('User', 'user_id'); 
    } 
} 

另一种模式,我还使用哨兵Cartalyst包

+0

你的'foo'函数在哪里?如果您有疑问,请告诉您究竟做了什么以及您为此特定代码获得的错误。 – 2014-11-09 10:20:45

+2

这个错误几乎肯定意味着你试图在QueryBuilder对象上调用'foo'而不是你的模型。这可能是由于在查询结束时不调用' - > get()'(或另一个执行语句的函数)。如果不是让我们看看你的“富”功能以及你如何称呼它。 – lukasgeiter 2014-11-09 11:51:24

回答

1

我终于明白什么是错误的例子。我有一个具有相同类名(用户)的迁移,并搞砸了用户模型。