mercredi 8 mai 2019

Data send from mobile did not insert into MySQL DB

I have develop a mobile apps using ionic and the apps can send data to the web that I develop using Laravel. The problem happen when the data send through the api cannot be stored in the database.

Below are the code that I write in my ionic (information.ts) and the (api) in Laravel

my code in ionic (information.ts)

 setInfoSmoker() {
    this.form = {
      daily_cig: this.daily,
      price_cig: this.price,
      no_of_cig: this.packet,
      quit_date: this.myDate,
    }

    this.restProvider.setInfoSmoker(this.form).subscribe(res => {
      this.strID = res.data;

      if (res.status == 200) {
        status
        "Information Has Been Fill";
        this.navCtrl.setRoot(PersonalPage);
      } else {
        "Fail to Fill Information ";
      }
    });
    console.log(this.form);
   }

my code in Laravel (api.php)

Route::namespace('Api')->group(function () {

   Route::post('smoker/info/', 'SmokerController@info');
});

my code in Laravel function in(SmokerController)

public function info(Request $request)
    {
        //$result = [];

        $info = new Information;
        $info->no_of_cig = $request->no_of_cig;
        $info->daily_cig = $request->daily_cig;
        $info->price_cig = $request->price_cig;
        $info->quit_date = $request->quit_date;
        $info->user_id = $request->user_id;

        $checkdate = $request->quit_date;
        $date = new Carbon($checkdate);
        $now = Carbon::now();

        $day = $date->diffInDays($now);
        $info->saving = (($request->price_cig / $request->no_of_cig) * $day * $request->daily_cig);

        $info->save();
        return response()->json([
            "status" => 200,
            "msg" => "",
            "data" => $info
        ]);
    }

The result should be the data send from the mobile save to the website database through the api.

Thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire