app/Http/Controllers/AdminBookingController.php
/**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
Show the form for creating a new resource.
@return \Illuminate\Http\Response
Show the form for creating a new resource . @return \ Illuminate \ Http \ Response
public function save(Request $request)
    {
        if(!$request->session()->has('quotation')) return redirect('/monthly')->withErrors("ไม่พบข้อมูลการจองพื้นที่");
        $rules = array('type' => 'required');
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails())  return redirect('/monthly')->withErrors($validator);
        $user = $request->session()->get('member');
        if ( $user->role != 2)  return redirect('/monthly')->withErrors("user permission denied.");
        $quotation = $request->session()->get('quotation');
        $rows = $quotation["rows"];
        $products = $quotation["products"];
        $arr_product = explode('|' , $products);
        $name = $quotation["productName"];
        $booking_code = date('YmdHms') . '-' . $user->id;
        foreach( $rows as $key => $row){
            $booking = Booking::create([
                'sale_at' => $row->opened_at,
                'userID' => $user->id,
                'userCode' => $user->code,
                'quantity' => count($arr_product),
                'totalPrice' => $row->price,
                'code' => $booking_code,
                'productName' => $name ,
                'status' => 'BK',
                'type' => $request->input('type'),
                'payment_type' => 2
            ]);
            $this->saveDetail($booking , $arr_product , $user);
        }
        $request->session()->forget('quotation');
        return view('adminbooking.success', ['rows' => $quotation['rows']
            , 'products' => $quotation['products']
            , 'productName' => $quotation['productName']
            , 'thai_date' => $quotation['thai_date']
            , 'total_price' => $quotation['total_price']
            , 'booking_code' => $booking_code
            , 'type' => $request->input('type')
        ]);
    }
public function save ( Request $ request ) { if ( ! $ request -> session ( ) -> has ( 'quotation' ) ) return redirect ( '/monthly' ) -> withErrors ( " ไม่พบข้อมูลการจองพื้นที่"); $ rules = array ( 'type' => 'required' ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) return redirect ( '/monthly' ) -> withErrors ( $ validator ) ; $ user = $ request -> session ( ) -> get ( 'member' ) ; if ( $ user -> role != 2 ) return redirect ( '/monthly' ) -> withErrors ( " user permission denied. " ) ; $ quotation = $ request -> session ( ) -> get ( 'quotation' ) ; $ rows = $ quotation [ " rows " ] ; $ products = $ quotation [ " products " ] ; $ arr_product = explode ( '|' , $ products ) ; $ name = $ quotation [ " productName " ] ; $ booking_code = date ( 'YmdHms' ) . '-' . $ user -> id ; foreach ( $ rows as $ key => $ row ) { $ booking = Booking :: create ( [ 'sale_at' => $ row -> opened_at , 'userID' => $ user -> id , 'userCode' => $ user -> code , 'quantity' => count ( $ arr_product ) , 'totalPrice' => $ row -> price , 'code' => $ booking_code , 'productName' => $ name , 'status' => 'BK' , 'type' => $ request -> input ( 'type' ) , 'payment_type' => 2 ] ) ; $ this -> saveDetail ( $ booking , $ arr_product , $ user ) ; } $ request -> session ( ) -> forget ( 'quotation' ) ; return view ( 'adminbooking.success' , [ 'rows' => $ quotation [ 'rows' ] , 'products' => $ quotation [ 'products' ] , 'productName' => $ quotation [ 'productName' ] , 'thai_date' => $ quotation [ 'thai_date' ] , 'total_price' => $ quotation [ 'total_price' ] , 'booking_code' => $ booking_code , 'type' => $ request -> input ( 'type' ) ] ) ; }
Show the form for creating a new resource.
Show the form for creating a new resource .