app/Http/Controllers/Backend/CalendarController.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)
    {
        $rules = array('open' => 'required', 'date' => 'required');
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails()) return response()->json(array('result' => false, 'message' => 'valid input.'));
        $count = 0;
        $arr = $request->input('open');
        for ($i = 0; $i < count($arr); $i++) {
            $open = (object)$arr[$i];
            if (isset($open->value)) {
                if ($open->value) {
                    if (!isset($open->calendarID))
                        $open->calendarID = 0;
                    $calendar = Calendar::where('id', $open->calendarID)->get()->first();
                    if (!isset($calendar)) {
                        $calendar = new Calendar();
                    }
                    $calendar->code = $open->code;
                    $calendar->zoneID = $open->id;
                    $calendar->name = $open->name;
                    $calendar->maxLock = $open->maxLock;
                    $calendar->row = $open->row;
                    $calendar->availableLock = ($open->maxLock - $open->close);
                    $calendar->price_type1 = $open->price_type1;
                    $calendar->price_type2 = $open->price_type2;
                    $calendar->active = $open->active;
                    $calendar->opened_at = $request->input('date') . ' 00:00:00';
                    $calendar->created_at = date("Y-m-d H:i:s");
                    $calendar->save();
                    $count++;
                } else {
                    if (isset($open->calendarID)) {
                        $calendar = Calendar::where('id', $open->calendarID)->delete();
                    }
                }
            }
        }
        return response()->json(array('result' => true, 'message' => 'success [' . $count . '].', 'id' => $request->input('date')));
    }
public function update ( Request $ request ) { $ rules = array ( 'open' => 'required' , 'date' => 'required' ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) return response ( ) -> json ( array ( 'result' => false , 'message' => 'valid input.' ) ) ; $ count = 0 ; $ arr = $ request -> input ( 'open' ) ; for ( $ i = 0 ; $ i < count ( $ arr ) ; $ i ++ ) { $ open = ( object ) $ arr [ $ i ] ; if ( isset ( $ open -> value ) ) { if ( $ open -> value ) { if ( ! isset ( $ open -> calendarID ) ) $ open -> calendarID = 0 ; $ calendar = Calendar :: where ( 'id' , $ open -> calendarID ) -> get ( ) -> first ( ) ; if ( ! isset ( $ calendar ) ) { $ calendar = new Calendar ( ) ; } $ calendar -> code = $ open -> code ; $ calendar -> zoneID = $ open -> id ; $ calendar -> name = $ open -> name ; $ calendar -> maxLock = $ open -> maxLock ; $ calendar -> row = $ open -> row ; $ calendar -> availableLock = ( $ open -> maxLock - $ open -> close ) ; $ calendar -> price_type1 = $ open -> price_type1 ; $ calendar -> price_type2 = $ open -> price_type2 ; $ calendar -> active = $ open -> active ; $ calendar -> opened_at = $ request -> input ( 'date' ) . ' 00:00:00' ; $ calendar -> created_at = date ( " Y-m-d H:i:s " ) ; $ calendar -> save ( ) ; $ count ++ ; } else { if ( isset ( $ open -> calendarID ) ) { $ calendar = Calendar :: where ( 'id' , $ open -> calendarID ) -> delete ( ) ; } } } } return response ( ) -> json ( array ( 'result' => true , 'message' => 'success [' . $ count . '].' , 'id' => $ request -> input ( 'date' ) ) ) ; }
Update the specified resource in storage.
Update the specified resource in storage .