I am selecting all the broadcasts that belong to the same organization as the authenticated user, this works perfectly with whereHas but what if i wanted to add a filter to display only the broadcasts where is_published is true
public static function indexQuery(NovaRequest $request, $query)
{
if (Auth::user()->isAdmin()) {
return $query;
}else{
return $query->whereHas('organizations', function($q){
$q->where('organization_id', Auth::user()->organization_id);
});
}
}
models
public function organizations()
{
return $this->belongsToMany('App\Models\Organization');
}
public function broadcasts()
{
return $this->belongsToMany('App\Models\Broadcast');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire