0

我有一个供应商排名表如下

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

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

}

我正在尝试执行此查询

$usersandranking= Supplierrank::with('supplier')->with(array('user'=>function($query) use($exceleve){
        $query->where('event','=',$exceleve);
    }))->orderBy('userid')->orderBy('rank')->get();

在这里你可以看到我正在尝试为 event == execelevent 的所有用户获取供应商排名

但查询正在从用户表中获取所有用户

任何我做错的想法

用户表如下所示

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

使用 DB::enableQueryLog() 后更新;和 dd(DB::getQueryLog());

我懂了

array(5) { [0]=> array(3) { ["query"]=> string(44) "select * from `users` where `id` = ? limit 1" ["bindings"]=> array(1) { [0]=> int(71) } ["time"]=> float(0.59) } [1]=> array(3) { ["query"]=> string(39) "select * from `users` where `event` = ?" ["bindings"]=> array(1) { [0]=> string(32) "Design Mission South Africa 2015" } ["time"]=> float(3.41) } [2]=> array(3) { ["query"]=> string(63) "select * from `supplierranks` order by `userid` asc, `rank` asc" ["bindings"]=> array(0) { } ["time"]=> float(366.02) } [3]=> array(3) { ["query"]=> string(1051) "select * from `suppliers` where `suppliers`.`id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 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