0

I dont know how to insert date data in database laragon in flutter app. I have done the GUI for the insert date using package "flutter_datetime_picker: ^1.1.5" but I dont know how to forward date data selected to database.

I have dont the select date as shown in code .dart below. I'm not sure how to connect it to api from database.

insertdate.dart

RaisedButton(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(5.0)),
                elevation: 4.0,
                onPressed: () {
                  DatePicker.showDatePicker(context,
                      theme: DatePickerTheme(
                        containerHeight: 210.0,
                      ),
                      showTitleActions: true,
                      minTime: DateTime(2019, 1, 1),
                      maxTime: DateTime(2030, 12, 31), onConfirm: (date) {
                    print('confirm $date');
                    departDate = '${date.year} - ${date.month} - ${date.day}';
                    setState(() {});
                  }, currentTime: DateTime.now(), locale: LocaleType.en);
                },
                child: Container(
                  alignment: Alignment.center,
                  height: 50.0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Row(
                        children: <Widget>[
                          Container(
                            child: Row(
                              children: <Widget>[
                                Icon(
                                  Icons.date_range,
                                  size: 25.0,
                                  color: Colors.black.withOpacity(0.5),
                                ),
                               new Text(
                                  // controller: dateDepartController,
                                  " $departDate",
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18.0),
                                ),
                              ],
                            ),
                          )
                        ],
                      ),
                      Text(
                        "  Change",
                        style: TextStyle(
                            color: Colors.black.withOpacity(0.5),
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0),
                      ),
                    ],
                  ),
                ),
                color: Colors.white.withOpacity(0.8),
              ),

Below is the API for post data date in laravel. All data can be updated when I test run API in the Postman. I just cant figured out how to post data in the flutter.

api

     public function PostTrip(Request $request)
         {
            $id = $request->id;
            $fr_country = $request->fr_country;
            $ar_country = $request->ar_country;
            $traveller_id = $request->taveller_id;
            $departDate = $request->departDate;
            $returnDate = $request->returnDate;

            $getId = User::where('id',$id)->first()->id;
            //// called country based on id ////
            $getFCountry = Countries::where('id',$fr_country)->first()->country;
            $getACountry = Countries::where('id',$ar_country)->first()->country;


             $user = PosTrip::create([
                'fr_country' =>$getFCountry,     
                'ar_country' =>$getACountry,           
                'traveller_id'=>$getId,
                'departDate'=>$departDate,
                'returnDate'=>$returnDate,

            ]);


                $datamsg = response()->json([
                'success' => array("text"=>"Done!")
                ]);
                return $datamsg->content();



         }

I want the date update in table in database.

3
  • First of all, laragon is a webserver, not API. So the question is invalid. Since you are using laragon, i'm guessing you are familiar with laravel. If you are, you can develop API in laravel. If you want to know how to post data to api, you can follow this post stackoverflow.com/questions/44645260/… Commented Sep 13, 2019 at 10:10
  • You can learn more about laravel api in laravel.com/docs/5.8/eloquent-resources and laravel.com/docs/5.8/routing Commented Sep 13, 2019 at 10:14
  • I have update the question.Its a function API that I have tried. Commented Sep 17, 2019 at 1:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.