AbdulBazith
4 months ago
85
29
Laravel

Get data from 3 tables with relationship laravel

Posted 4 months ago by AbdulBazith

Guys i have a problem in my hotel management system project.

i have a product_type table (parent table) with columns

id
type_name

product table (child table)

id
product_type_id(fk)
product_name

order_table with columns

id
product_id(fk)
qty
rate
total

here whats my doubt is i need to fetch records from order_table. but the record must be grouped by the product_type with the total . how can i achieve it.

the product_type and product has relationship

this is my product model

 public function product_type()
    {
        return $this->belongsTo('App\ProductType', 'product_type_id');
    }

this is my product_type model

   public function product()
    {
        return $this->hasMany('App\Product', 'product_type_id');
    }

this is my query,

 $order = Order::where ('hotel_id',Auth::user()->hotel_id)->get();

i need to fetch records based the product_type wise. it mus be grouped based on product_type.

Kindly some one help please.

Please sign in or create an account to participate in this conversation.