About Laravel query problems with multiple conditions?

Source: Internet
Author: User
related query questions about laravel multiple conditions:

Table order Order Form:

    • idSelf-Increment ID

    • order_idOrder number

    • paid_datePayment Time

Table order_product Order Product table:

    • idSelf-Increment ID

    • fk_order_idOrder number, FOREIGN key

    • product_nameName

    • product_numberNumber

    • quantityNumber

Table relationships:

Order-1:n-order_product

Demand:
The following native SQL is implemented through the Laravel eloquent ORM:

SELECT * FROM order as A inner joins order_product as B on a.order_id=b.fk_order_id where (a.paid_date between ' 2016-01-01 ' and ' 2016-09-01 ') and b.product_name like '%apple iphone% '

Manual read several times, try to do, but at present only through the Wherehas realization b.product_name like this part of the condition, when the two tables all exist conditions, it is not done.
Hope Laravel predecessors, thank you!

PS. Supplement:
Currently, there are paginate requirements for filtering and retrieving the list page.

Workaround:

Class Order extends model{public    function scopeproducts ($query)    {        return $query->join (' Order_ Product ', function ($join) {            $join->on (' order.order_id ', ' = ', ' order_product.fk_order_id ');}}    
Order::p roducts ()->where (...);

The above is about laravel multiple conditions of the related query problem content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

Related articles:

Laravel Associated queries get only part of the data for a management object

Laravel Associated Query problems

Laravel Associated query articles and article authors

  • 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.