Laravel eloquent ORM multi-condition query

Source: Internet
Author: User
first, the demand: The most common in data search is to call the same method query, and the query field may be one or several of the fields together to combine the query, such as: The search for the list, basically are a few fields randomly combined search. Then in model you need to judge the combination of that field, how to combine.         online for a long time, Laravel Group also asked a few, have said no written, so I write a bar. Don't say much, see Code: [php]  View Plain  copy function findbyparam ($param  = array ())       {        $select  = new customer ();        if  (Isset ($param [' name '])  &&  '  !=  $param [' name '])        {          $select  =  $select->where (' customer.name ',  ' = ',  $param [' name ']];       }        if  (Isset ($param [' phone '])  &&  '  !=  $param [' phone ']]        {          $select  =  $select->where (' customer.phone ',  ' = ',  $param [' phone ']];       }        if  (Isset ($param [' email '])  &&  '  !=  $param [' email ']]        {           $select  =  $select->where (' customer.email ',  ' = ',  $param [' Email ']);       }       if  (isset ($param [' Tel '] )  &&  '  !=  $param [' Tel ']]        {           $select  =  $select->where (' customer.tel ',  ' = ',  $param [' Tel ']);       }       if  (isset ($param [' QQ '])  &&  '  !=  $param [' QQ ']]        {           $select  =  $select->where (' customer.qq ',  ' = ',  $param [' QQ '] );       }       

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.