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?
The substr helper method is a convenient helper built on top of PHP's mb_substr function (unlike PHP's mb_substr function, substr does not provide a way to change the encoding that is used) that is used to return a portion of a string.
Searching Eloquent models Imagine you need to provide a search for users. Using Eloquent you can perform a search like this: User::query() ->where('name', 'LIKE', "%{$searchTerm}%") ->orWhere('email', 'LIKE', "%{$searchTerm}%") ->get();
Eloquent is an object relational mapper (ORM) that is included by default within the Laravel framework. An ORM is software that facilitates handling database records by representing data as objects, working as a layer of abstraction on top of the database engine used to store an application's data.
An Eloquent model is just a PHP class, that allows you to do two things: Interact with the database table as a whole. For example: $users = User::all(); gets all users. Represent a single row in the table.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With