Home > database >  Undefined Array Key /What_do_you
Undefined Array Key /What_do_you

Time:11-10

i am trying to send email when a user received offers on his posted job. But i am getting undefined variable key /what_do_you error. Angular version 14 and laravel version is 8. The code which i shared is on laravel. ReceiverOffer is an API and i am trying to send email. I need to include What_do_you in the email body as it contains the Job title

Here is my code

public function ReceiverOffer()

    {

        $inputs = $this->request->all();

        $v = Validator::make($inputs, [

            'job_post_id' => 'required',

            'amount' => 'required',

        ]);



        if($v->fails()){

            return R::ValidationError($v->errors());

        }



        $jobData = [

            'job_post_id' => $inputs['job_post_id'],

            'amount' => $inputs['amount'],

            'detail' => $inputs['detail'],

            'offer_by_id' => Auth::id()

        ];



       DB::beginTransaction();     

       try {

            $dt = JobOffer::create($jobData);

            DB::commit();

            $data = JobOffer::where('id', $dt->id)->first();
            $user = User::where('id', Auth::id())->with('profile')->first();

            // Job Offer Received By Poster
            $msg = '<p>
            Someone has made an offer for your job '.$inputs['what_do_you'].' See if they are the right person for the job.</p>';
            Mail::to($user->email)->send(new GeneralEmail(['name' =>' JobTasker - Payment Request - '.$inputs['what_do_you'],'to' =>$user->name],' JobTasker', $msg));



            return R::Success('Job Offer Send. Successfully', $data);



       } catch (Exception $e) {

         DB::rollback();

         return R::SimpleError("Can't save data");  

       }

    }

When Save Offer button is pressed, the job offer is saved and at same time email should be sent. But i am having issue in email sending.

saveOffer() : void {
    if (this.offerAmount < 1) {
      this.ts.warning('Enter some budget to submit the offer'); 
    }
    if (this.offerNote == ''){
      this.ts.warning('Enter your bid description!');  
    }
    else {
      let postData = {
        job_post_id : this.selectedPostId,
        amount : this.offerAmount,
        detail : this.offerNote
      };

      this.ds.saveOffer(postData).subscribe((resp: any) => {
        if (resp.success) {
          this.alreadyOffered = true;
          let selectedData = this.jobList.filter((i:any) => i.id == this.selectedPostId);
          selectedData[0].total_offer.push(resp.data);
          this.modalRef?.hide();
          this.offerAmount = 0;
          this.ts.success('The offer submited successfully');
        } else {
          this.ts.warning('There is something wrong, please try again later');
        }
      });
    }
 

}

console error

network tab error

CodePudding user response:

As i can see you are using the wrong variable here '.$inputs['what_do_you'].'.

you need to call as below

'.$data['what_do_you'].'

your front end angular code is correct

  • Related