Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use orWhere in laravel

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report