So I have 2 models in Laravel 5.3. Practice and Offer, they have a many to many relationship which is set up and working. I can attach offers to practices etc. I want to retrieve all offers that are not already related to the practice.
The logged in user also belongs to the practice with practice_id.
In my controller I am passing in $offer in the constructor which just relates to all offers. I've tried using the reject() method as below but I'm getting nothing back, and I can't figure it out.
If I use $this->offer I get everything.
$query = $this->offer->reject(function($offer){
return $offer->whereHas('practices', function($q) {
return $q->where('practice_id', Auth::user()->practice_id);
});
});
Please help.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire