Try with whereNested
$thing = Equipment::whereHas('agreement', function($q)use($month)
{
$q->where('equipment.status', '=', 'Active')
->where('maintenance_months', 'like', '%'.$month.'%')
->whereNested(function($q) {
$q->where('status', '=', 'Active')
->orWhere('status', '=', 'Unsigned')
->orWhere('status', '=', 'Cancel on expiry');
});
})->get();
And an alternative solution (but i'm not really sure about it)
$thing = Equipment::whereHas('agreement', function($q)use($month)
{
$q->where('equipment.status', '=', 'Active')
->where('maintenance_months', 'like', '%'.$month.'%')
->whereIn('status', ['Active', 'Unsigned', 'Cancel on expiry']);
})->get();
This was the (hack) of a solution - it also checks if the company and location is active...
$equipment = Equipment::where('status', 'Active') /** Is equipment active? */
->whereHas('agreement', function($q)use($month) /** Is agreement linked? */
{
$q->where('maintenance_months', 'like', '%'.$month.'%') /** Only a certain month */
->whereIn('status', ['Unsigned', 'Active', 'Cancel on Expiry']) /** Is agreement active? */
->whereHas('company', function($q)
{
$q->where('status', 'Active'); /** Is company active? */
});
})->whereHas('location', function($q)use($areas)
{
$q->where('status', 'Active') /** Is location active? */
->whereIn('area_id', $areas); /** Only certain areas */
})->with('location.company')->Get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community