When I do something like SomeModel::with(\'user\')
it returns a Query\\Builder
instance. How can I get this instance without need call the with()
Use the static query
method:
$query = User::query();
Additionally, you can use the when
method to chain these conditionals directly onto the query builder itself:
$results = SomeModel::query()->when(condition(), function ($query) {
$query->where(...);
})->get();
This is functionally equivalent to the imperative if
clause.