jeudi 28 mars 2019

Adding extra queries to whereHas

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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UiprRy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire