Laravel 关系有说服力的状态
你好,我是拉拉维尔的新手 我试图用Elounce检索数据,但我必须添加一个与关系相关的条件 我的模型Laravel 关系有说服力的状态,laravel,Laravel,你好,我是拉拉维尔的新手 我试图用Elounce检索数据,但我必须添加一个与关系相关的条件 我的模型 class DemandeInscription extends Model { public function user(){ return $this->belongsTo('App\User','tuteur_id'); } } 这是我在控制器上试过的 $demandes= DemandeInscription::with('user','meet'
class DemandeInscription extends Model
{
public function user(){
return $this->belongsTo('App\User','tuteur_id');
}
}
这是我在控制器上试过的
$demandes= DemandeInscription::with('user','meet','enfant')
->where('confirmation','=',0)->user()
->where('phone_verified_at','!=',null)
->orderBy('created_at','desc')->paginate(10);
我得到了错误
Arguments
"Call to undefined method Illuminate\Database\Eloquent\Builder::user()"
你可以用这种方式得到它
或
或者使用本地作用域,在用户模型内编写此作用域
public function scopeVerified($query){
return $query->where('phone_verified_at','!=',null);
}
$demandes= DemandeInscription::with(['user' => function($query){
$query->verified();
},'meet','enfant'])
->where('confirmation','=',0)
->orderBy('created_at','desc')->paginate(10);
你能接受这个答案以便其他人也能得到帮助吗?
$demandes= DemandeInscription::whereHas(['user' => function($query){
$query->where('phone_verified_at','!=',null);
}])
->orwhereHas('meet','enfant')
->where('confirmation','=',0)
->orderBy('created_at','desc')->paginate(10);
public function scopeVerified($query){
return $query->where('phone_verified_at','!=',null);
}
$demandes= DemandeInscription::with(['user' => function($query){
$query->verified();
},'meet','enfant'])
->where('confirmation','=',0)
->orderBy('created_at','desc')->paginate(10);