Exemplo n.º 1
0
 public function properties()
 {
     $qb = Property::active()->orderBy('checkout_at', 'DESC');
     $properties = $qb->get();
     $content = view('frontend.sitemap.properties', ['properties' => $properties])->render();
     return response($content, 200)->header('Content-Type', 'text/xml');
 }
Exemplo n.º 2
0
 public function getXMLLamudi()
 {
     $return = [];
     $qb = Property::active();
     AddressHelper::addAddressQueryScope($qb);
     //By exclusive
     $qb->selectRaw('properties.*, IF(Pac.slug = \'exclusive\', 1, 0) as is_exclusive');
     $qb->leftJoin('package_property AS PP', 'PP.property_id', '=', 'properties.id')->leftJoin('packages AS Pac', 'PP.package_id', '=', 'Pac.id')->leftJoin('package_categories AS PC', 'PC.id', '=', 'Pac.package_category_id');
     $qb->groupBy('properties.id');
     $qb->orderBy('is_exclusive', 'DESC');
     $sellProperties = $qb->where('for_sell', 1)->get();
     foreach ($sellProperties as $property) {
         if ($property->hasThumbnail() || $property->hasFloorplan()) {
             $propertyData = $this->generatePropertyData($property, 'sell');
             $return[] = $propertyData;
         }
     }
     $rentProperties = $qb->where('for_rent', 1)->get();
     foreach ($rentProperties as $property) {
         if ($property->hasThumbnail() || $property->hasFloorplan()) {
             $propertyData = $this->generatePropertyData($property, 'rent');
             $return[] = $propertyData;
         }
     }
     return response()->xml($return, 200, [], 'Properties', null, 'Data');
 }
Exemplo n.º 3
0
 public function getExclusiveProperties($take = 5)
 {
     $qb = Property::active()->with('type')->orderBy(DB::raw('RAND()'))->take($take);
     $sellQb = clone $qb;
     $sellExclusiveProperties = $sellQb->select(DB::raw('properties.*, "sell" AS exclusive_type'))->whereHas('packages', function ($query) {
         $query->whereHas('category', function ($query2) {
             $query2->where('slug', 'sell');
         });
         $query->where('slug', 'exclusive');
     })->get()->all();
     $rentQb = $qb;
     $rentExclusiveProperties = $qb->select(DB::raw('properties.*, "rent" AS exclusive_type'))->whereHas('packages', function ($query) {
         $query->whereHas('category', function ($query2) {
             $query2->where('slug', 'rent');
         });
         $query->where('slug', 'exclusive');
     })->get()->all();
     $properties = array_merge($rentExclusiveProperties, $sellExclusiveProperties);
     shuffle($properties);
     $properties = array_slice($properties, 0, $take);
     return $properties;
 }
Exemplo n.º 4
0
 public function getSearch(Request $request)
 {
     $for = $request->input('search.for');
     $priceDefaultFrom = 10000000;
     $priceDefaultTo = 100000000000;
     $qb = Property::active();
     AddressHelper::addAddressQueryScope($qb);
     if ($request->input('search.for') == 'sell') {
         $qb->where('for_sell', 1);
     } elseif ($request->input('search.for') == 'rent') {
         $qb->where('for_rent', 1);
     }
     if ($request->has('search.keyword')) {
         $qb->where(function ($query) use($request) {
             $query->orWhere('address', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('description', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('property_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('province_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('city_name', 'LIKE', '%' . $request->input('search.keyword') . '%')->orWhere('subdistrict_name', 'LIKE', '%' . $request->input('search.keyword') . '%');
         });
     }
     $citySearch = '';
     if ($request->has('search.subdistrict')) {
         $qb->where('subdistrict', $request->input('search.subdistrict'));
         $citySearch = AddressHelper::getAddressLabel($request->input('search.subdistrict'), 'subdistrict');
     }
     if ($request->has('search.city')) {
         $qb->where('city', $request->input('search.city'));
         if (!empty($citySearch)) {
             $citySearch .= ', ';
         }
         $citySearch .= AddressHelper::getAddressLabel($request->input('search.city'), 'city');
     }
     if ($request->has('search.province')) {
         $qb->where('province', $request->input('search.province'));
         if (empty($citySearch)) {
             $citySearch = AddressHelper::getAddressLabel($request->input('search.province'), 'province');
         }
     }
     if ($request->has('search.rooms')) {
         $qb->where('rooms', '>=', $request->input('search.rooms'));
     }
     if ($request->has('search.type')) {
         $qb->where('property_type_id', $request->input('search.type'));
     }
     if ($request->has('search.price')) {
         $price = explode(',', $request->input('search.price'));
         if (isset($price[0])) {
             $priceDefaultFrom = $price[0];
             if ($for == 'sell') {
                 $qb->where('sell_price', '>=', $priceDefaultFrom);
             } elseif ($for == 'rent') {
                 $qb->where('rent_price', '>=', $priceDefaultFrom);
             } else {
                 $qb->where(function ($query) use($priceDefaultFrom) {
                     $query->where('sell_price', '>=', $priceDefaultFrom)->orWhere('rent_price', '>=', $priceDefaultFrom);
                 });
             }
         }
         if (isset($price[1])) {
             $priceDefaultTo = $price[1];
             if ($for == 'sell') {
                 $qb->where('sell_price', '<=', $priceDefaultTo);
             } elseif ($for == 'rent') {
                 $qb->where('rent_price', '<=', $priceDefaultTo);
             } else {
                 $qb->where(function ($query) use($priceDefaultTo) {
                     $query->where('sell_price', '<=', $priceDefaultTo)->orWhere('rent_price', '<=', $priceDefaultTo);
                 });
             }
         }
     }
     $resultCount = $qb->count();
     //By exclusive
     $qb->selectRaw('properties.*, IF(Pac.slug = \'exclusive\', 1, 0) as is_exclusive');
     $qb->leftJoin('package_property AS PP', 'PP.property_id', '=', 'properties.id')->leftJoin('packages AS Pac', 'PP.package_id', '=', 'Pac.id')->leftJoin('package_categories AS PC', 'PC.id', '=', 'Pac.package_category_id');
     $qb->groupBy('properties.id');
     $qb->orderBy('is_exclusive', 'DESC');
     //Sorts
     $sortKeys = explode('_', $request->input('sort', 'date_desc'));
     if ($sortKeys[0] == 'price') {
         if ($for != 'all' && $for) {
             $sortColumn = $for . '_' . $sortKeys[0];
         } else {
             $sortColumn = 'all_price';
         }
     } else {
         $sortColumn = 'checkout_at';
     }
     $sortOrder = isset($sortKeys[1]) ? $sortKeys[1] : 'desc';
     if ($sortColumn == 'all_price') {
         $qb->orderBy('sell_price', $sortOrder);
         $qb->orderBy('rent_price', $sortOrder);
     } else {
         $qb->orderBy($sortColumn, $sortOrder);
     }
     $properties = $qb->paginate(16);
     $properties->appends(['sort' => $request->input('sort'), 'search' => $request->input('search')]);
     $sorts = ['date_desc' => trans('property.index.sort_by.date_desc'), 'date_asc' => trans('property.index.sort_by.date_asc'), 'price_asc' => trans('property.index.sort_by.price_asc'), 'price_desc' => trans('property.index.sort_by.price_desc')];
     return view('frontend.property.public.search', ['for' => $for, 'paginator' => $properties, 'citySearch' => $citySearch, 'resultCount' => $resultCount, 'priceDefaultFrom' => $priceDefaultFrom, 'priceDefaultTo' => $priceDefaultTo, 'sorts' => $sorts]);
 }