app/Http/Controllers/CheckinController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        if($id == null) return response()->json(array('result'=>false , 'message'=>'Booking id can not be null.'));
         $rules = array(
                'id' =>'required',
                'code' =>'required',
                'canCheckIn' => 'required|boolean:true',
                'bookingDetail' => 'required|array'
        );
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails()) return response()->json(array('result'=>false , 'message'=>'invalid input field.'));
        $date = new DateTime();
        $date->setTimezone(new DateTimeZone('Asia/Bangkok'));
        $booking = Booking::where('id' , $id)->first();
        $booking->status = 'CN';
        $booking->checkin_at =  $date->format('Y-m-d H:i:s');
        $result = $booking->save();
        if(!$result) return response()->json(array('result'=>false , 'message'=>'Booking id $id check-in has error.')); 
        BookingDetail::where('bookingID' , $id)->update(['status' => 'CN']);
        return response()->json(array('result'=>true , 'message'=>'success.'));
    }
public function update ( Request $ request , $ id ) { if ( $ id == null ) return response ( ) -> json ( array ( 'result' => false , 'message' => 'Booking id can not be null.' ) ) ; $ rules = array ( 'id' => 'required' , 'code' => 'required' , 'canCheckIn' => 'required|boolean:true' , 'bookingDetail' => 'required|array' ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) return response ( ) -> json ( array ( 'result' => false , 'message' => 'invalid input field.' ) ) ; $ date = new DateTime ( ) ; $ date -> setTimezone ( new DateTimeZone ( 'Asia/Bangkok' ) ) ; $ booking = Booking :: where ( 'id' , $ id ) -> first ( ) ; $ booking -> status = 'CN' ; $ booking -> checkin_at = $ date -> format ( 'Y-m-d H:i:s' ) ; $ result = $ booking -> save ( ) ; if ( ! $ result ) return response ( ) -> json ( array ( 'result' => false , 'message' => 'Booking id $id check-in has error.' ) ) ; BookingDetail :: where ( 'bookingID' , $ id ) -> update ( [ 'status' => 'CN' ] ) ; return response ( ) -> json ( array ( 'result' => true , 'message' => 'success.' ) ) ; }
Update the specified resource in storage.
Update the specified resource in storage .