How to pass parameters in Transaction method in Laravel

$result= DB::transaction(function () use ($complaintId, $attach) {
            askSupport::create([
                'uid'=>Str::uuid(),
                'userId'=>Auth::guard('college')->user()->id,
                'roleId'=>$this->roleId,
                'complaintId'=>$complaintId,
                'department'=>$this->departmentInput,
                'subject'=>$this->subjectInput,
                'attachment'=>$attach,
                'complaint'=>$this->complaintInput,
                'status'=>1
            ]);

            supportCommunication::create([
                'userId'=>Auth::guard('college')->user()->id,
                'roleId'=>$this->roleId,
                'complaintId'=>$complaintId,
                'comText'=>$this->departmentInput,
                'comType'=>$this->subjectInput,
                'attachment'=>$attach,
                'status'=>1
            ]);

        });

Leave a Comment