How do I convert a similar MySQL query to Laravel Eloquent?

SELECT * FROM `books` WHERE books.type = 'rare' AND - $value < $result

That’s how I think it should be

$books= DB::table('books')
                        ->where('type ','=', 'rare')
                        ->whereRaw('band - $value < $result')   // Syntax error

I don’t understand how to work with dynamic variables here.


Please try it:

$books= DB::table('books')
            ->where('type ', 'rare')
            ->whereRaw('band - ? < ?', [$value, $result])

Leave a Reply

Your email address will not be published. Required fields are marked *