Reputation: 25
SELECT * FROM `books` WHERE books.type = 'rare' AND books.band - $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.
Upvotes: 0
Views: 68
Reputation: 192
Always use Eloquent with laravel.
$books = Books::where('type','rare')->whereRaw("band - $value < $result")->get();
Upvotes: 0
Reputation: 351
Try like this:
$books= DB::table('books')
->where('type ','=', 'rare')
->whereRaw(\DB::raw("band - $value < $result"))
->get();
Upvotes: 0
Reputation: 1212
Please try it:
$books= DB::table('books')
->where('type ', 'rare')
->whereRaw('band - ? < ?', [$value, $result])
->get();
Upvotes: 1
Reputation: 12188
try use parenthesis, it's simple:
$books= DB::table('books')
->where('type ','=', 'rare')
->whereRaw("band - {$value} < {$result}")->get();
you can do it using binding also:
$books= DB::table('books')
->where('type ','=', 'rare')
->whereRaw("band - ? < ?",[$value,$result])->get();
Upvotes: 0