By adding the following code snippet to an Eloquent Model I can force the Model to include certain SQL constraints on all database calls ever being made using that Model:
public function newQuery($excludeDeleted = true)
{
// Make use of all functionalities of the "newQuery" method of the
// parent Eloquent class; and add constraints to that instance.
$sql = parent::newQuery($excludeDeleted);
// Example constraint
$sql->where('example', 'test');
return $sql;
}
However, when adding constraints in e.g. the controller, those additional constraints will always be added AFTER the above WHERE `example` = 'test
constraint.
Is it possible to force a certain constraint AFTER all other constraints are added? Instead of BEFORE? I have this need to comply with the order of existing database indexes.