Support the ongoing development of Laravel.io →
Database
Last updated 1 year ago.
0

Try,

/*
SELECT brands.url_key,devices.* FROM brands 
INNER JOIN devices ON devices.brand_id=brands.id 
WHERE brands.url_key='samsung-mobile-phones'
*/
    
    $result = DB::table('brands')
                 ->join('devices', 'devices.brand_id', '=', 'brands.id')
                 ->where('brands.url_key', 'samsung-mobile-phones' );

If you set up a relationship between brands and devices in the brands model then you should be able to do this,

    $result = Brands::where('url_key', 'samsung-mobile-phones' )->with('devices');
   // the return structure would be different than the other query
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.