I'm using yajra datatable package and I have some orders tables, there are :
- orders : id,order_code,duration,status .....
- order_products (storing order from available product) : id,order_id(reference from orders),product_id,type,price ,created_at ....
- order_vps_custom (storing order from custom product) : id,order_id(reference from orders),package,ram,cpu,created_at...
There is 2 cases :
case 1 : If user choose from available product
I store order_code and etc into orders table as parent and then insert into table order_packages as child table of orders
case 2 : If user custom vps order
I store order_code and etc into orders table as parent and then insert into table order_vps_custom as child table of orders
And I have no idea to select with eager load,with expected output on my page like below:
VPS | REGIESTERED AT | STATUS
order_packages and order_vps_custom on same table
I've try with this on controller:
$model = Order::with(['order_products','vps_custom'])->get();
$dTable = DataTables()->of($model)->addIndexColumn()
->editColumn('vps',function($data){
return $data->vps->package;
})
Order (model) :
public function order_products()
{
return $this->hasMany(OrderProduct::class,'order_id','id');
}
public function vps_custom()
{
return $this->hasMany(OrderVpsCustom::class,'order_id','id');
}
here is my result array :
Can anyone help me out ?
