Reputation: 1220
I try to make a particular query but i'm not sure how to achieve this , i would like to access to saison table
{{ \App\Licencies::where(['structure_id' => Auth::user()->structure->id])->where(['saison_id->dt_fin' , '<' , \Carbon\Carbon::now()])->count() }}
here the saison() relation in my model , that i can access very well
$licencie->saison->dt_fin < \Carbon\Carbon::now()
someone knows to right query ? thanks a lot in advance
Upvotes: 0
Views: 38
Reputation: 6646
Thanks for the explanation in the comment.
In the Laraval documentation there is the following example:
// Retrieve all posts with at least one comment containing words like foo%
$posts = Post::whereHas('comments', function ($query) {
$query->where('content', 'like', 'foo%');
})->get();
Which can easily be transformed for your purpose:
// Retrieve all licencies where the saison has a dt_fin before now
$licencies = \App\Licencies::whereHas('saison', function ($query) {
$query->where('dt_fin', '<', \Carbon\Carbon::now());
})->get();
If it still returns errors, let us know! (kinda hard to test without carbin and a structure that is equal to yours)
Upvotes: 1