Level 75
You may need raw Expressions but yes look at mysql manual for examples.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This code works:
Product::where('active', 1)
->where('standard', 1)
->leftJoin('family_modifiers', 'family_modifiers.id', '=', 'products.family_id')
->select('products.*',DB::raw('(products.price*family_modifiers.modifier)+products.price as modified'))
->orderBy($request->column, $request->order)
->orderBy('secondary_category_id')->get();
This does not:
return $builder->where('number', 'LIKE', '%' . $value . '%')
->whereHas('modifier', function (\Illuminate\Database\Eloquent\Builder $query) use ($value){
$query->where('family', '=', '10')
->select('products.*',DB::raw('(products.price*family_modifiers.modifier)+products.price as modified'));
});
NOTE: They are two separate queries. I am not replacing the first one, but rather trying to adapt it to a situation where I use \Illuminate\Database\Eloquent\Builder.
Please or to participate in this conversation.