Answer the question
In order to leave comments, you need to log in
Is there a way to cancel any condition in QueryBuilder (Laravel 5)?
Suppose there is such a request
At some point in time, before the moment of sampling from the database, it is necessary to cancel the condition on the user's age.
Here's how to do it? $query = DB::table('users')->whereAge(18);
Answer the question
In order to leave comments, you need to log in
I found the answer myself :)
foreach ((array) $query->wheres as $key => $where)
{
if ($where['column'] == 'age')
{
unset($query->wheres[$key]);
$query->wheres = array_values($query->wheres);
}
}
$query = DB::table('users');
if(){
//code
} else {
$query = $query->whereAge(18);
}
$query= $query->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question