Answer the question
In order to leave comments, you need to log in
How does whereHas work in Laravel?
How does whereHas work in Laravel in this example:
$orders = OrderModel::whereHas('User', function ($query) {
if ($request->has('term')) {
$query->where('LastName', 'like', $request->term);
}
});
$query->where()
and what query will it build otherwise? $query = "SELECT * FROM TABLE";
if ($request->data) {
$query+= " lEFT JOIN TABLE 2 ON..."
}
Answer the question
In order to leave comments, you need to log in
How does whereHas work in Laravel?
Instead of ->get() or ->first() you can call ->toSql() it will show the current query template
How many queries will Laravel build if the $query->where() condition is met, and what query will it build otherwise?This can be easily found out from the database logs or the debug panel for Laravel.
And is it possible to dynamically create a query based on input data, something like this:Maybe. And what prevents you from building such requests?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question