app/Http/Controllers/Backend/CalendarController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $rules = array('open' => 'required', 'dates' => 'required');
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails()) return response()->json(array('result' => false, 'message' => 'valid input.'));
        $dates = $request->input('dates');
        $opens = $request->input('open');
        foreach ($dates as $key => $date) {
            foreach ($opens as $key => $open) {
                $open = (object)$open;
                if (isset($open->value) && $open->value == true) {
                    $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 = $date . ' 00:00:00';
                    $calendar->created_at = date("Y-m-d H:i:s");
                    $calendar->save();
                }
            }
        }
        return response()->json(array( 'result' => true , 'message' => 'success.' ));
    }
public function store ( Request $ request ) { $ rules = array ( 'open' => 'required' , 'dates' => 'required' ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) return response ( ) -> json ( array ( 'result' => false , 'message' => 'valid input.' ) ) ; $ dates = $ request -> input ( 'dates' ) ; $ opens = $ request -> input ( 'open' ) ; foreach ( $ dates as $ key => $ date ) { foreach ( $ opens as $ key => $ open ) { $ open = ( object ) $ open ; if ( isset ( $ open -> value ) && $ open -> value == true ) { $ 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 = $ date . ' 00:00:00' ; $ calendar -> created_at = date ( " Y-m-d H:i:s " ) ; $ calendar -> save ( ) ; } } } return response ( ) -> json ( array ( 'result' => true , 'message' => 'success.' ) ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//echo '<br>'.$date; // echo "true";