the query I wrote may at some point contain columns that are null which causes the query to return an empty array even though there is a value in the campaigns table. This is caused because the query cant make a join if the column values are null. I am trying to write an if statement to return the campaign even if its values are null but its still returning an empty array. If I run the query in the if statement it returns me what I am looking for I just cant get the if statement to trigger.
public function getCampaigns(Request $request)
{
$authUser = auth()->user();
$business = $authUser['business_id'];
$query = campaigns::join('offers', 'campaigns.offer_id', '=', 'offers.id')
->join('conditionals', 'campaigns.conditional_id', '=', 'conditionals.id')
->join('triggers', 'campaigns.offer_id', '=', 'triggers.id')
->select('campaigns.*',
'triggers.name AS trigger_name',
'offers.name AS offer_name',
'offers.reward_amount as offer_reward_amount',
'offers.plaid_category_id as offer_plaid_id',
'conditionals.dollars_min',
'conditionals.dollars_max',
'conditionals.dollars_more',
'conditionals.xDays as days_since_last_purchase',
'conditionals.xDate as date_since_last_purchase',
'conditionals.xPercent as percentage_more',
'conditionals.xPurchases as purchases_x_times',
'conditionals.start_date',
'conditionals.end_date',
'conditionals.plaid_category_id')
// ->whereNull('campaigns.trigger_id', 'campaigns.offer_id', 'campaigns.conditional_id')
->where('campaigns.business_id', '=', $business);
if ($query->count() === 0){
$query = campaigns::select('*')->where('business_id', '=', $business);
}
return $query->get();
}