Reputation: 7076
I use Laravel 5.3
My laravel eloquent is like this :
$query = User::where('year', '=', (string)$object->year)
->where(\DB::raw('substr(code, 1, 3)'), '=', 511)
->get();
I try like that, but it does not work
How can I solve it?
Upvotes: 5
Views: 30942
Reputation: 21
Late on this thread but for anyone who is having the same issue with the aforementioned topic i found a solution by concatenating the value. For example :-
return User::whereRaw('SUBSTRING(column, -2, 2) = '.$value)->get();
Hope this helps.
Upvotes: 2
Reputation: 503
you forgot to put comma after '=' sign. try this .
$query = User::where('year', '=', (string)$object->year)
->where(\DB::raw('substr(code, 1, 3)'), '=' , 511)
->get();
Upvotes: 5