I'm still trying to wrap my head around whereHas() method. My case is this. I want to pull all users that belong to class
This is relations
Classes model
public function users()
{
return $this->belongsToMany('App\User')->withTimestamps();
}
User model
public function classes()
{
return $this->belongsToMany('App\Classes')->withTimestamps();
}
controller
$class_us = User::whereHas('classes', function ($query) {
$query->where('class',1);
})->get();
When I do dd($class_us) i get an empty collection
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire