dimanche 25 novembre 2018

failed to update cnic which i set as unique?

Failed to update cnic.. What is the issue? I have three tables. I have set cnic as unique. Cnic is same in all tables when i add Member cnic saves in all tables .Something issue in this code. i can update everything but when i try to update cnic it's show alert "Failed to Update Member!".How can i update cnic??

public function updateMember(Request $request)
{

    $cnic = $request->input('cnic');
    $name = $request->input('name');
    $address = $request->input('address');
    $mobile = $request->input('mobile_number');


    $qualification = $request->input('qualification');
    $profession = $request->input('profession');
    $experience = $request->input('experience');
    $employed = $request->input('employed');

    $interestedProvince = $request->input('interested-province');
    $interestedDivision = $request->input('interested-division');
    $interestedDistrict = $request->input('interested-district');
    $department = $request->input('department');
    $position = $request->input('position');
    $board = $request->input('board');
    $committee_name = $request->input('committee_name');
    $testing = $request->input('testing');
    $memberID = $request->get('cnic');

    $rules = array(
        'cnic' => 'required',
    );

    $validator = Validator::make($request->all(), $rules);

    // if the validator fails, redirect back to the form
    if ($validator->fails()) {
        return redirect('/dashboard')
            ->withErrors($validator)
            ->withInput();

    } else {


        $memberData = (new Member())->where('cnic', '=', $cnic)->update([
            'cnic' => $cnic,
            'name' => $name,
            'address' => $address,
            'mobile' => $mobile,


        ]);

        $memberData1 = (new MemberDetail())->where('cnic', '=', $cnic)->update([

            'cnic' => $cnic,
            'qualification' => $qualification,
            'profession' => $profession,
            'experience' => $experience,
            'are_you_employed' => $employed,

        ]);

        $deleteAllRecords = (new MemberInterestDepartment())->where('cnic', '=', $cnic)->delete();
        if ($deleteAllRecords) {
            for ($q = 0; $q < count($testing); $q = $q + 4) {

                $SaveInterest = new MemberInterestDepartment();
                $SaveInterest->cnic = $cnic;
                $SaveInterest->department = $testing[$q];
                $SaveInterest->position = $testing[$q + 1];
                $SaveInterest->board = $testing[$q + 2];
                $SaveInterest->committee = $testing[$q + 3];
                $SaveInterest->interested_province = $interestedProvince;
                $SaveInterest->interested_division = $interestedDivision;
                $SaveInterest->interested_district = $interestedDistrict;

                $SaveInterest->save();
            }

        }


        if ($memberData && $memberData1) {
            return redirect()->to('/dashboard')->with(Session::flash('alert-success', 'Member Updated Successfully!'));
        } else {
            return redirect()->back()->with(Session::flash('alert-danger', 'Failed to Update Member!'))->withInput();
        }


    }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire