Trying to integrate "if condition" inside model relation. But It doesnt work.
$customer_index = Customer::where('firm_id', $firm_id)
->with(['company', 'tires', 'vehicles'])
->withCount(['tires', 'vehicles'])
->orderBy('id', 'desc');
my Customer.php model
public function vehicles()
{
if(isset($this->company->is_fleet)){
return $this->hasMany('App\Models\CustomerVehicle', 'fleet_id', 'company_id');
}
return $this->hasMany('App\Models\CustomerVehicle');
}