Reputation: 1101
8 project now everything working ok but i have question that in mysql i can run this
select * from table where mid(column_name,1,4) = 5
can i do something like this in laravel relation
like i have user
table and every user has voucher
i mean can i do something like this
User::getVoucherRelation()->where(mid(created_at,1,4),'=',$value)->get();
Model_name::Relation()->where(mid(column_name,1,6),'=',$value)->get();
ect thanks
Upvotes: 1
Views: 333
Reputation: 9161
You can try with the function whereRaw(), i.e.:
User::getVoucherRelation()->whereRaw("mid(created_at,1,4) = $value")->get();
Model_name::Relation()->whereRaw("mid(column_name,1,6) = $value")->get();
You can review the functions here: https://laravel.com/docs/5.7/queries#raw-expressions
Upvotes: 2