/**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $rules = [];
     $routeName = $this->route()->getName();
     if ($this->route('id')) {
         $property = Property::findOrFail($this->route('id'));
     } else {
         $property = new Property();
     }
     if (in_array($routeName, ['frontend.property.create.process', 'frontend.property.edit.process'])) {
         $rules = $this->getCreateRules($property);
     } elseif (in_array($routeName, ['frontend.property.details.process'])) {
         $rules = $this->getDetailRules($property);
     } elseif (in_array($routeName, ['frontend.property.map.process'])) {
         $rules['latitude'] = 'required_if:point_map,1';
         $rules['longitude'] = 'required_if:point_map,1';
     } elseif (in_array($routeName, ['frontend.property.packages.process'])) {
         $allowedPackages = implode(',', Package::lists('id')->toArray());
         $rules['action'] = 'required';
         foreach ($this->input('action', []) as $idx => $action) {
             $rules['action.' . $idx] = 'in:' . $allowedPackages;
             $package = Package::findOrFail($action);
             $allowedFeatures = implode(',', $package->features->lists('id')->toArray());
             foreach ($this->input('features.' . $package->id, []) as $featureIdx => $feature) {
                 $rules['features.' . $package->id . '.' . $featureIdx] = 'in:' . $allowedFeatures;
             }
         }
     } elseif (in_array($routeName, ['frontend.property.review.process'])) {
         $allowedPaymentMethods = array_keys(Payment::getPaymentMethods(null, TRUE));
         $allowedPaymentMethods = implode(',', $allowedPaymentMethods);
         if ($this->input('action') == 'purchase') {
             $rules['agree_tc'] = 'required';
             $rules['payment_method'] = 'required|in:' . $allowedPaymentMethods;
         }
     }
     return $rules;
 }
 public function postPropertyOrderReview(PropertyFormRequest $request, $id)
 {
     $user = Auth::user();
     $property = Property::findOrFail($id);
     if ($request->input('action') == 'purchase') {
         $order = $property->getCartOrder();
         $payment_method = Payment::getPaymentMethods($request->input('payment_method'), TRUE);
         $payment = new Payment(['total_amount' => $order->total_amount, 'payment_method' => $payment_method['machine_name'], 'status' => Payment::STATUS_UNPAID]);
         $payment->user()->associate($user);
         $payment->order()->associate($order);
         $payment->save();
         $order->generateOrderNumber();
         $order->save();
         switch ($payment_method['machine_name']) {
             case Payment::METHOD_DOKU_CREDIT_CARD:
                 return redirect()->route('frontend.property.payment', ['id' => $property->id]);
                 break;
             default:
                 $order->status = Order::STATUS_PENDING;
                 $order->save();
                 return redirect()->route('frontend.property.success', ['id' => $property->id]);
                 break;
         }
     } elseif ($request->input('action') == 'change_package') {
         return redirect()->route('frontend.property.packages', ['id' => $property->id]);
     }
 }