Is there a more elegant / better solution to the below code? At present, I have to repeat a lot of query just to add an extra 'where' into the query.
if ($common == true) {
$products = self::with(array(
'metal',
'metal.fixes.currency',
'metal.fixes' => function($query) use ($currency_id){
$query->where('currency_id', '=', $currency_id);
}))
->where('metal_id', '=', $metal_id)
->where('product_type_id', '=', $product_type_id)
->where('common', '=', 1) // This line is the only difference
between the two Queries
->get();
}
else {
$products = self::with(array(
'metal',
'metal.fixes.currency',
'metal.fixes' => function($query) use ($currency_id){
$query->where('currency_id', '=', $currency_id);
}))
->where('metal_id', '=', $metal_id)
->where('product_type_id', '=', $product_type_id)
->get();
}