Example #1
0
 /**
  * insert()  - POST request.
  *
  * Input fields:
  *
  * ['user_id']     = The user id reserved for the system.
  * ['region']      = Region where they wil departure.
  * ['destination'] = The destination address  | 2 = Calais & 1 = Duinkerke
  * ['date']        = The data of arrival.
  * ['name']        = The name of the driver.
  * ['email']       = The email address of the driver.
  * ['telephone']   = The telephone number of the driver.
  * ['places']      = The available places in the car(s).
  *
  * @param Request $request
  *
  * @return response
  */
 public function insert(Request $request)
 {
     // MySQL database insert.
     $trip = new Trips();
     $trip->user_id = auth()->gaurd('api')->user()->id;
     $trip->region = $request->region;
     $trip->destination = $request->destination;
     $trip->date = strtotime($request->date);
     // UNIX timestamp.
     $trip->name = $request->name;
     $trip->email = $request->email;
     $trip->telephone = $request->telephone;
     $trip->places = $request->places;
     if ($trip->save()) {
         $dataArray = ['status' => ['code' => 200, 'message' => 'The trip is created.']];
     } elseif (!$trip->save()) {
         Log::error();
         $dataArray = ['status' => ['code' => 500, 'message' => 'Trip inserted.']];
     }
     return response()->json($dataArray)->header('Content-Type', 'application/json', 200);
 }