[Vuejs]-How to add new field & value from selected joined table

1👍

You need to use DB::raw

But remember, raw statements will be injected into the query as strings, so you should be extremely careful to not create SQL injection vulnerabilities.

With DB::raw your code will look like this:

$getmaterial = ContractProduct::select(
        'product_item.ref_rof_id',
        'product_item.code',
        'product_item.qty_stock',
        'contract_product.qty_taken',
         ContractProduct::raw('product_item.qty_stock - contract_product.qty_taken as qty_exceed') 
    )
    ->where('ref_rof_id', $getrof->ref_rof_id)
    ->join('product_item', 'contract_product.ref_product_id', '=', 'product_item.code')
    ->get();

    $data['getquoid'] = $getquoid;
    $data['getmaterial'] = $getmaterial;
    $view = $this->module_path . '.next-create';
    
    return response()->view($view, $data);

Leave a comment