具有关系的Laravel Sentry用户模型

时间:2015-01-16 10:46:39

标签: php laravel eloquent relationship cartalyst-sentry

我有一个用户模型:

use Cartalyst\Sentry\Users\Eloquent\User as SentryModel;

class User extends SentryModel {

    public function raspberries() {
        return $this->hasMany('Raspberry');
    }

}

和SentryModel:

<?php

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

class SentryModel extends Eloquent implements UserInterface, RemindableInterface {

    /**
     * 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');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}

和Rasberry模型:

class Raspberry extends Eloquent{

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

现在我想从我记录的用户中选择所有Rasberries:

$data = Sentry::getUser()->raspberries()->paginate(10);

但这不起作用,我收到错误消息:

  

BadMethodCallException

     

调用未定义的方法   照亮\数据库\查询\生成器::覆盆子()

为什么?

0 个答案:

没有答案