app/Http/Controllers/PaymentController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Payment  $payment
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Payment $payment)
    {
        $validatedData = $request->validate([
            'opening_fee'           => 'required_without_all:embassy_student_fee,service_solicitor_fee,other',
            'embassy_student_fee'   => 'required_without_all:opening_fee,service_solicitor_fee,other',
            'service_solicitor_fee' => 'required_without_all:opening_fee,embassy_student_fee,other',
            'other'                 => 'required_without_all:opening_fee,embassy_student_fee,service_solicitor_fee',
        ]);
        $total_amount = $request->opening_fee + 
                        $request->embassy_student_fee + 
                        $request->service_solicitor_fee + 
                        $request->other;
        $total_amount_paid = array_sum(array_column($request->payment, 'amount_paid'));
        $due               = $total_amount - $total_amount_paid;
        $date              = Carbon::parse($request->date)->toDateTimeString();
        Payment::find($payment->id)->update([
            'location'              => $request->location,
            'opening_fee'           => $request->opening_fee,
            'embassy_student_fee'   => $request->embassy_student_fee,
            'service_solicitor_fee' => $request->service_solicitor_fee,
            'other'                 => $request->other,
            'dues'                  => $due,
            'comments'              => $request->comments,
            'created_at'            => $date,
        ]);
        PaymentType::where('payment_id', $payment->id)->delete();
        foreach ($request->payment as $key => $value) {
            $payment_type             = isset($value['payment_type']) ? $value['payment_type'] : NULL;
            $amount_paid              = isset($value['amount_paid']) ? $value['amount_paid'] : NULL;
            $bank_name                = isset($value['bank_name']) ? $value['bank_name'] : NULL;
            $bank_charge              = isset($value['bank_charge']) ? $value['bank_charge'] : NULL;
            $name_on_card             = isset($value['name_on_card']) ? $value['name_on_card'] : NULL;
            $card_number              = isset($value['card_number']) ? $value['card_number'] : NULL;
            $expiry_date              = isset($value['expiry_date']) ? $value['expiry_date'] : NULL;
            $pos_machine              = isset($value['pos_machine']) ? $value['pos_machine'] : NULL;
            $approval_code            = isset($value['approval_code']) ? $value['approval_code'] : NULL;
            $cheque_number            = isset($value['cheque_number']) ? $value['cheque_number'] : NULL;
            $cheque_verified          = isset($value['cheque_verified']) ? $value['cheque_verified'] : 1;
            $online_verified          = isset($value['online_verified']) ? $value['online_verified'] : 1;
            $bkash_salman_verified    = isset($value['bkash_salman_verified']) ? $value['bkash_salman_verified'] : 1;
            $bkash_corporate_verified = isset($value['bkash_corporate_verified']) ? $value['bkash_corporate_verified'] : 1;
            $bank_name                = isset($value['bank_name']) ? $value['bank_name'] : NULL;
            $bank_charge              = isset($value['bank_charge']) ? $value['bank_charge'] : NULL;
            $phone_number             = isset($value['phone_number']) ? $value['phone_number'] : NULL;
            $deposit_date             = isset($value['deposit_date']) ? $value['deposit_date'] : NULL;
            $card_type                = isset($value['card_type']) ? $value['card_type'] : NULL;
            $created_at               = isset($value['created_at']) ? $value['created_at'] : NULL;
            $after_charge = $amount_paid - (($bank_charge / 100) * $amount_paid);
            PaymentType::create([
                'payment_id'               => $payment->id,
                'payment_type'             => $payment_type,
                'card_type'                => $card_type,
                'name_on_card'             => $name_on_card,
                'card_number'              => $card_number,
                'expiry_date'              => $expiry_date,
                'pos_machine'              => $pos_machine,
                'approval_code'            => $approval_code,
                'phone_number'             => $phone_number,
                'cheque_number'            => $cheque_number,
                'bank_name'                => $bank_name,
                'online_verified'          => $online_verified,
                'cheque_verified'          => $cheque_verified,
                'bkash_salman_verified'    => $bkash_salman_verified,
                'bkash_corporate_verified' => $bkash_corporate_verified,
                'bank_charge'              => $bank_charge,
                'amount_paid'              => $amount_paid,
                'amount_received'          => $after_charge,
                'deposit_date'             => $deposit_date,
                'created_at'               => $created_at,
            ]);
        }
        return redirect()->back()->with('success', 'Payment has been edited successfully');
    }
public function update ( Request $ request , Payment $ payment ) { $ validatedData = $ request -> validate ( [ 'opening_fee' => 'required_without_all:embassy_student_fee,service_solicitor_fee,other' , 'embassy_student_fee' => 'required_without_all:opening_fee,service_solicitor_fee,other' , 'service_solicitor_fee' => 'required_without_all:opening_fee,embassy_student_fee,other' , 'other' => 'required_without_all:opening_fee,embassy_student_fee,service_solicitor_fee' , ] ) ; $ total_amount = $ request -> opening_fee + $ request -> embassy_student_fee + $ request -> service_solicitor_fee + $ request -> other ; $ total_amount_paid = array_sum ( array_column ( $ request -> payment , 'amount_paid' ) ) ; $ due = $ total_amount - $ total_amount_paid ; $ date = Carbon :: parse ( $ request -> date ) -> toDateTimeString ( ) ; Payment :: find ( $ payment -> id ) -> update ( [ 'location' => $ request -> location , 'opening_fee' => $ request -> opening_fee , 'embassy_student_fee' => $ request -> embassy_student_fee , 'service_solicitor_fee' => $ request -> service_solicitor_fee , 'other' => $ request -> other , 'dues' => $ due , 'comments' => $ request -> comments , 'created_at' => $ date , ] ) ; PaymentType :: where ( 'payment_id' , $ payment -> id ) -> delete ( ) ; foreach ( $ request -> payment as $ key => $ value ) { $ payment_type = isset ( $ value [ 'payment_type' ] ) ? $ value [ 'payment_type' ] : NULL ; $ amount_paid = isset ( $ value [ 'amount_paid' ] ) ? $ value [ 'amount_paid' ] : NULL ; $ bank_name = isset ( $ value [ 'bank_name' ] ) ? $ value [ 'bank_name' ] : NULL ; $ bank_charge = isset ( $ value [ 'bank_charge' ] ) ? $ value [ 'bank_charge' ] : NULL ; $ name_on_card = isset ( $ value [ 'name_on_card' ] ) ? $ value [ 'name_on_card' ] : NULL ; $ card_number = isset ( $ value [ 'card_number' ] ) ? $ value [ 'card_number' ] : NULL ; $ expiry_date = isset ( $ value [ 'expiry_date' ] ) ? $ value [ 'expiry_date' ] : NULL ; $ pos_machine = isset ( $ value [ 'pos_machine' ] ) ? $ value [ 'pos_machine' ] : NULL ; $ approval_code = isset ( $ value [ 'approval_code' ] ) ? $ value [ 'approval_code' ] : NULL ; $ cheque_number = isset ( $ value [ 'cheque_number' ] ) ? $ value [ 'cheque_number' ] : NULL ; $ cheque_verified = isset ( $ value [ 'cheque_verified' ] ) ? $ value [ 'cheque_verified' ] : 1 ; $ online_verified = isset ( $ value [ 'online_verified' ] ) ? $ value [ 'online_verified' ] : 1 ; $ bkash_salman_verified = isset ( $ value [ 'bkash_salman_verified' ] ) ? $ value [ 'bkash_salman_verified' ] : 1 ; $ bkash_corporate_verified = isset ( $ value [ 'bkash_corporate_verified' ] ) ? $ value [ 'bkash_corporate_verified' ] : 1 ; $ bank_name = isset ( $ value [ 'bank_name' ] ) ? $ value [ 'bank_name' ] : NULL ; $ bank_charge = isset ( $ value [ 'bank_charge' ] ) ? $ value [ 'bank_charge' ] : NULL ; $ phone_number = isset ( $ value [ 'phone_number' ] ) ? $ value [ 'phone_number' ] : NULL ; $ deposit_date = isset ( $ value [ 'deposit_date' ] ) ? $ value [ 'deposit_date' ] : NULL ; $ card_type = isset ( $ value [ 'card_type' ] ) ? $ value [ 'card_type' ] : NULL ; $ created_at = isset ( $ value [ 'created_at' ] ) ? $ value [ 'created_at' ] : NULL ; $ after_charge = $ amount_paid - ( ( $ bank_charge / 100 ) * $ amount_paid ) ; PaymentType :: create ( [ 'payment_id' => $ payment -> id , 'payment_type' => $ payment_type , 'card_type' => $ card_type , 'name_on_card' => $ name_on_card , 'card_number' => $ card_number , 'expiry_date' => $ expiry_date , 'pos_machine' => $ pos_machine , 'approval_code' => $ approval_code , 'phone_number' => $ phone_number , 'cheque_number' => $ cheque_number , 'bank_name' => $ bank_name , 'online_verified' => $ online_verified , 'cheque_verified' => $ cheque_verified , 'bkash_salman_verified' => $ bkash_salman_verified , 'bkash_corporate_verified' => $ bkash_corporate_verified , 'bank_charge' => $ bank_charge , 'amount_paid' => $ amount_paid , 'amount_received' => $ after_charge , 'deposit_date' => $ deposit_date , 'created_at' => $ created_at , ] ) ; } return redirect ( ) -> back ( ) -> with ( 'success' , 'Payment has been edited successfully' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .