Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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();

Last updated 9 years ago.
0

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(); 
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.