public function features($id, $all = TRUE) { $package = Package::findOrFail($id); $return = []; foreach ($package->features as $feature) { if (empty(round($feature->pivot->price))) { if ($all) { $return[$feature->id] = ['name' => $feature->name, 'price' => 0, 'category' => $package->category->slug]; } } else { $return[$feature->id] = ['name' => $feature->name, 'price' => $feature->pivot->price, 'category' => $package->category->slug]; } } return response()->json($return); }
/** * 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 postPropertyPackages(PropertyFormRequest $request, $id) { $user = Auth::user(); $property = Property::findOrFail($id); $propertyCartOrder = $property->getCartOrder(); if (empty($propertyCartOrder)) { $order = new Order(['status' => Order::STATUS_CART]); $order->property()->associate($property); $order->user()->associate($user); $order->save(); } else { $order = $propertyCartOrder; } //Clear Order Item first $order->items()->delete(); $property->packages()->detach(); $orderTempAddons = []; foreach ($request->input('action', []) as $idx => $action) { $package = Package::findOrFail($action); $features = $request->input('features.' . $package->id, []); $addons = []; if ($package->isExclusive) { $exclusiveCategory = 'level_' . $package->category->slug; } else { $exclusiveCategory = FALSE; } foreach ($features as $idy => $feature) { $featureObj = $package->features->find($feature); $addons[] = $featureObj->id; if (!in_array($featureObj->id, $orderTempAddons)) { $orderTempAddons[] = $featureObj->id; $orderItem = new OrderItem(['item' => $featureObj->id, 'item_type' => 'feature', 'quantity' => 1, 'price' => $featureObj->pivot->price, 'net_price' => $featureObj->pivot->price, 'sort_order' => $idy + 1]); $order->items()->save($orderItem); } } //Associate first package to Order temporarily if ($idx == 0) { $order->package()->associate($package); } $property->packages()->attach([$package->id => ['addons' => implode('|', $addons)]]); } $order->calculate(); $order->save(); return redirect()->route('frontend.property.review', ['id' => $property->id]); }
public function edit($id) { $property = Property::withTrashed()->findOrFail($id); $owner = $property->user ? $property->user->email : ''; $defaultLatitude = empty($property->latitude) ? config('app.default_latitude') : $property->latitude; $defaultLongitude = empty($property->longitude) ? config('app.default_longitude') : $property->longitude; if (empty($property->latitude) || empty($property->longitude)) { $mapDefault = true; } else { $mapDefault = false; } $sellPackage = old('sell_package') ? Package::findOrFail(old('sell_package')) : null; $rentPackage = old('rent_package') ? Package::findOrFail(old('rent_package')) : null; $packages = $property->packages()->with('category')->get(); foreach ($packages as $package) { if ($package->category->slug == 'rent' && !$rentPackage) { $rentPackage = $package; } elseif ($package->category->slug == 'sell' && !$sellPackage) { $sellPackage = $package; } } $viewData = ['owner' => $owner, 'property' => $property, 'defaultLatitude' => $defaultLatitude, 'defaultLongitude' => $defaultLongitude, 'mapDefault' => $mapDefault, 'sellPackage' => $sellPackage, 'rentPackage' => $rentPackage]; foreach (PackageCategory::all() as $packageCategory) { ${$packageCategory->slug . 'PackageOptions'} = $packageCategory->packages->pluck('name', 'id')->all(); $viewData[$packageCategory->slug . 'PackageOptions'] = ${$packageCategory->slug . 'PackageOptions'}; } return view('admin.property.edit', $viewData); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $user = Auth::user(); $propertyTypeAllowedValues = implode(',', PropertyType::lists('id')->all()); $rentPriceTypeAllowedValues = implode(',', array_keys(Property::getRentTypeLabel())); $viewingSchedulesAllowedValues = implode(',', array_keys(Property::getViewingScheduleOptionLabel())); $propertyFurnishingAllowedValues = implode(',', array_keys(Property::getFurnishingLabel())); $orientationAllowedValues = implode(',', array_keys(Property::getOrientationLabel())); $propertyType = PropertyType::find($this->input('property_type_id')); if ($user->is('administrator')) { $rules['owner'] = 'required|email'; } $rules['property_name'] = 'required'; $rules['province'] = 'required'; $rules['city'] = 'required'; $rules['subdistrict'] = 'required'; $rules['address'] = 'required'; $rules['postal_code'] = ''; $rules['property_type_id'] = 'required|in:' . $propertyTypeAllowedValues; $rules['garage_size'] = 'integer'; $rules['carport_size'] = 'integer'; $rules['rooms'] = 'required'; $rules['bathrooms'] = 'required'; $rules['maid_rooms'] = 'integer'; $rules['maid_bathrooms'] = 'integer'; $rules['furnishing'] = 'required|in:' . $propertyFurnishingAllowedValues; $rules['phone_lines'] = 'integer'; $rules['electricity'] = 'integer'; $rules['orientation'] = 'in:' . $orientationAllowedValues; $rules['for_sell'] = 'required|in:0,1'; $rules['sell_price'] = 'required_if:for_sell,1'; $rules['sell_viewing_schedule'] = 'required_if:for_sell,1'; foreach ($this->input('sell_viewing_schedule', []) as $idx => $sellViewingSchedule) { $rules['sell_viewing_schedule.' . $idx] = 'in:' . $viewingSchedulesAllowedValues; } $rules['for_rent'] = 'required|in:0,1'; $rules['rent_price'] = 'required_if:for_rent,1'; $rules['rent_price_type'] = 'required_if:for_rent,1|in:' . $rentPriceTypeAllowedValues; $rules['rent_viewing_schedule'] = 'required_if:for_rent,1'; foreach ($this->input('rent_viewing_schedule', []) as $idx => $rentViewingSchedule) { $rules['rent_viewing_schedule.' . $idx] = 'in:' . $viewingSchedulesAllowedValues; } $certificateAllowedValues = implode(',', array_keys(Property::getCertificateLabel())); $rules['land_size'] = 'numeric|min:1'; $rules['land_dimension.length'] = 'numeric|required_with:land_dimension.width'; $rules['land_dimension.width'] = 'numeric|required_with:land_dimension.length'; if ($propertyType && $propertyType->slug == 'land') { $rules['land_size'] .= '|required'; } $rules['building_size'] = 'numeric|min:1'; $rules['building_dimension.length'] = 'numeric|required_with:building_dimension.width'; $rules['building_dimension.width'] = 'numeric|required_with:building_dimension.length'; if ($propertyType && $propertyType->slug != 'land') { $rules['building_size'] .= '|required'; } $rules['floor'] = 'numeric'; $rules['certificate'] = 'in:' . $certificateAllowedValues; $rules['virtual_tour_url'] = 'url'; //$rules['description'] = 'required|min:10|max:300'; $rules['latitude'] = 'required_if:point_map,1'; $rules['longitude'] = 'required_if:point_map,1'; $allowedPackages = implode(',', Package::lists('id')->toArray()); $rules['sell_package'] = 'required_if:for_sell,1|in:' . $allowedPackages; if ($this->has('sell_package')) { $package = Package::findOrFail($this->input('sell_package')); $allowedFeatures = implode(',', $package->features->lists('id')->toArray()); foreach ($this->input('features.sell', []) as $featureIdx => $feature) { $rules['features.sell.' . $featureIdx] = 'in:' . $allowedFeatures; } } $rules['rent_package'] = 'required_if:for_rent,1|in:' . $allowedPackages; if ($this->has('rent_package')) { $package = Package::findOrFail($this->input('rent_package')); $allowedFeatures = implode(',', $package->features->lists('id')->toArray()); foreach ($this->input('features.rent', []) as $featureIdx => $feature) { $rules['features.rent.' . $featureIdx] = 'in:' . $allowedFeatures; } } return $rules; }