try to put the field-name in Backticks:
$query->where('speed', '>', `speed_limit` + 10);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to query my DB and return results where the 'speed' column is 10+km/h over the 'speed_limit' column.
I am using a query builder to take variables out of the request and build them similar to this:
if($overSpeed != false){ $query = $query->where('speed', '>', 'speed_limit' + 10); }
I've tried variations of the following: $query = $query->where('speed', '>', 'speed_limit' + 10); $query = $query->where('speed', '>', '(speed_limit + 10)');
And I cannot seemt o get it right. Any help would be appreciated.
Try a raw query
$query->whereRaw('speed > speed_limit + ?', [10])
//or
$query->whereRaw('speed > speed_limit + 10')
Please or to participate in this conversation.