Php 如何在Laravel 4.2中建立多个关系

Php 如何在Laravel 4.2中建立多个关系,php,mysql,laravel-4.2,Php,Mysql,Laravel 4.2,我有一个这样的用户模型 class User extends Eloquent implements UserInterface, RemindableInterface { use UserTrait, RemindableTrait; /** * The database table used by the model. * * @var string */ protected $table = 'users';

我有一个这样的用户模型

class User extends Eloquent implements UserInterface, RemindableInterface {

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

    public function answer(){
        return $this->hasMany('Answer','user_id');
    }

    public function supplierranking(){
        return $this->hasMany('Supplierrank','userid','id');
    }
}
Class Supplierrank extends Eloquent{
    public function supplier(){
        return $this->belongsTo('Supplier','supplierid','id');
    }

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

}
Class Supplier extends Eloquent{
    public function supplierranks(){
        return $this->hasMany('Supplierrank','supplierid');
    }

}
$usersandranking = User::where('event','=',$exceleve)->with('supplierranking')->orderBy('id')->get();
现在,每个用户将按照如下所示的排名模型对一家公司进行排名

class User extends Eloquent implements UserInterface, RemindableInterface {

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

    public function answer(){
        return $this->hasMany('Answer','user_id');
    }

    public function supplierranking(){
        return $this->hasMany('Supplierrank','userid','id');
    }
}
Class Supplierrank extends Eloquent{
    public function supplier(){
        return $this->belongsTo('Supplier','supplierid','id');
    }

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

}
Class Supplier extends Eloquent{
    public function supplierranks(){
        return $this->hasMany('Supplierrank','supplierid');
    }

}
$usersandranking = User::where('event','=',$exceleve)->with('supplierranking')->orderBy('id')->get();
我能够获得用户的排名详细信息,但我还必须获得已从供应商表中排名的公司的详细信息

看起来像这样

class User extends Eloquent implements UserInterface, RemindableInterface {

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

    public function answer(){
        return $this->hasMany('Answer','user_id');
    }

    public function supplierranking(){
        return $this->hasMany('Supplierrank','userid','id');
    }
}
Class Supplierrank extends Eloquent{
    public function supplier(){
        return $this->belongsTo('Supplier','supplierid','id');
    }

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

}
Class Supplier extends Eloquent{
    public function supplierranks(){
        return $this->hasMany('Supplierrank','supplierid');
    }

}
$usersandranking = User::where('event','=',$exceleve)->with('supplierranking')->orderBy('id')->get();
我所做的查询如下所示

class User extends Eloquent implements UserInterface, RemindableInterface {

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

    public function answer(){
        return $this->hasMany('Answer','user_id');
    }

    public function supplierranking(){
        return $this->hasMany('Supplierrank','userid','id');
    }
}
Class Supplierrank extends Eloquent{
    public function supplier(){
        return $this->belongsTo('Supplier','supplierid','id');
    }

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

}
Class Supplier extends Eloquent{
    public function supplierranks(){
        return $this->hasMany('Supplierrank','supplierid');
    }

}
$usersandranking = User::where('event','=',$exceleve)->with('supplierranking')->orderBy('id')->get();
它给我提供了用户详细信息和排名,但没有供应商名称

有人能帮我吗