简体   繁体   中英

Laravel Advanced Search Query

im building a car ( car , bus ... ) seller website, i have tables like :

Brands :

id , name (bmw) , category (car , bus ) 

Models :

id , name ( 1.16, 3.20)  , brands_id 

Car_Sale :

id , brand_id , model_id , price , member_id 

Properties:

id , name( color , fuel ..) , value ( red , gasoline ) , car_sale_id

i have lots of options for properties table ( about 20 ) , what is the best way to handle this query ? how do you do in laravel ? should i use joins ? how can i check all of this tables and fields ?

Any ideas? Any Example Codes etc.? Thank you !

You need to model properly your relationships , once you done with that you can use Eloquent has many through or querying your relations .

Also if you need to join relationships with the Laravel query builder this is easy task too.

An example join:

 DB::table('users')
        ->join('contacts', 'users.id', '=', 'contacts.user_id')
        ->join('orders', 'users.id', '=', 'orders.user_id')
        ->select('users.id', 'contacts.phone', 'orders.price')
        ->get();

I hope this can help you a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM