dimanche 8 novembre 2015

Laravel Eloquent Query Builder (with JOIN)

Tables

VENDOR
id    name    approved

PRODUCT
id    name    price    instock    fky_prod_vendor_id

Relationship

VENDOR(hasMany products()) <- (one-to-many) -> (hasOne vendor())PRODUCT

Query

How can I get all the products in-stock of a approved vendor using Eloquent given that the relationships are defined in Model?

My SQL is as following, but I need to use Eloquent relationship to achive the following.

select product.id
from   product, vendor
where  product.fky_prod_vendor_id = vendor.id
and    vendor.approved = 'y'
and    product.instock  > 0

Thanks

K



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire