如何通过连接 laravel 中的四个表来更新列

How to update a column by joining four tables in laravel

我有四张桌子

我正在尝试使用 laravel

将列 number_of_products_sold 更新为某个值

我试过的是:

$qty = 1;

$m = DB::table('products_products')
    ->join(
        'products_products_mileage_gaps',
        'products_products.id',
        '=',
        'products_products_mileage_gaps.entry_id'
    )
    ->join(
        'products_product_mileage_gap',
        'products_products_mileage_gaps.related_id',
        '=',
        'products_product_mileage_gap.id'
    )
    ->join(
        'products_mileage_gap',
        'products_mileage_gap.id',
        '=',
        'products_product_mileage_gap.mileage_gap_id'
    )
    ->where('products_product_mileage_gap.number_of_products', '>', 0)
    ->where('products_mileage_gap.name', '=', $mileage_name)
    ->where('products_products.id', '=', $id)
    ->update(
        array(
            'products_product_mileage_gap.number_of_products_sold' => $qty
        )
    );

此处number_of_products_sold不更新

如何更新列

为什么要将四个 table 加在一起。这是一个通过控制器添加或更新多个 table 的示例。

public function processEmployee(Request $request)
    {

      
        $data = $request->all();


        
        $user =  User::create([
       
        'name'     =>$data['emp_name'],
        'email'    =>$data['email'],
        
       
    ]);

        $emp =  Employee::create([
        'photo'                => $emp_image,
        'name'                 => $data['emp_name'],
        'code'                 => $data['emp_code'],
        'status'               => $data['emp_status'],
        'email'               => $data['email'],
         'gender'               => $data['gender'],
               
        'qualification'        => $data['qualification'],
        'emergency_number'     => $data['emer_number'],
        'pan_number'           => $data['pan_number'],
        'father_name'          => $data['father_name'],
        'current_address '     => $data['current_address'],
        'permanent_address'    => $data['permanent_address'],
        'formalities'          => $data['formalities'],
        'offer_acceptance'     => $data['offer_acceptance'],
        'probation_period'     => $data['prob_period'],
      
        'department'           => $data['department'],
        'salary'               => $data['salary'],
        'account_number'       => $data['account_number'],
        'bank_name'            => $data['bank_name'],
        'ifsc_code'            => $data['ifsc_code'],
        'pf_account_number'    => $data['pf_account_number'],
        'un_number'            => $data['un_number'],
         'pf_status'            => $data['pf_status'],
      
        
        'user_id'              => $user->id,
        
        ]);

        $userRole =  UserRole::create([
      
        'role_id' => $data['role'],
        'user_id' => $user->id,
        

       ]),
        
    ]);
        if(isset($emp,  $user, $userRole)) {
              return redirect()->route('employee-manager')
                  ->with('message',
                   'Employee Successfully Registered.');
              }else{
                  return redirect()->to($this->getRedirectUrl())
                    ->withInput($request->input())->with('error',
                   'Action Failed Please try again.');
              }
      

        

    }