Home > database >  Laravel Eloquent Collection Where Condition Closure on Column Value
Laravel Eloquent Collection Where Condition Closure on Column Value

Time:12-22

I'm trying to do something like as follows:

$block = MatStock::whereHas('matDims', function (Builder $query) use ($request) {
    $query->where('width', $request->width)
        ->where('height', $request->height)
        ->where('thickness', $request->thickness)
        ->where('length', function ($column) use ($request) {
            return $column/$request->length > 0
            // how can i do that where condition?
        })
});

My question is in last where condition. I hope my question is clear. Thank you.

CodePudding user response:

whereRaw should do the trick

->whereRaw('(length / ?) > 0', [$request->length])
  • Related