Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use orWhere in laravel

Shulou Source: shulou.com Published: 2022-06-02 04:24:57 10月26日 Update

This article mainly shows you "how to use orWhere in laravel", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use orWhere in laravel" this article.

The where conditional query under the laravel framework is very simple, so I won't write it here. Here we mainly record the stitching of orWhere multi-conditional or query statements that are not commonly used. Examples are as follows:

(1) SQL statement:

Select `id`from `user` where (`email` = 'admin@phpernote.com' and `password` =' 123456') or (`mobile` = '13681127231' and `password` =' 123456')

Laravel model statement:

User::select (['id'])-> where (function ($query) use ($userName, $password) {$query- > where (' password','= '123456')-> where (' email','=', 'admin@phpernote.com') })-> orWhere (function ($query) use ($userName, $password) {$query- > where ('password',' =', '123456')-> where ('mobile',' = '13681127231');})-> first ()

(2) SQL statement:

Select count (*) from `user`where `type` = 1 and `valid_ type` = 2 and (`valid_ end`

< 1560738570 or `valid_begin` >

1560738570)

Laravel model statement:

$model = User::where ('type', 1)-> where (' valid_type','=', 2)-> where (function ($query) {$query- > where ('valid_end',', 1560738570);})-> first ()

(3) SQL statement:

Select count (*) from `user`where `valid_ type` = 2 or (`valid_ type` = 3 and (`valid_ end`)

< 1560738570 or `valid_begin` >

1560738570))

Laravel model statement:

$model = User::where (function ($query) {$query- > where ('valid_type', 2);})-> orWhere (function ($query) {$query- > where (' valid_type','=', 3)-> where (function ($query) {$query- > where ('valid_end',', 1560738570);});})-> first () The above is all the contents of the article "how to use orWhere in laravel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Sentences content articles conditions learning help query ordinary not very easy to understand more organization framework knowledge examples editing industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Shulou Tech Info MySQL vpn