public static function getById($id) { $favorites = Favorite::where('user_id', $id)->get(); $ad_ids_array = []; foreach ($favorites as $favorite) { $ad_ids_array[] = $favorite->ad_id; } $ads = Ad::whereIn('id', $ad_ids_array)->paginate(20); return $ads; }
public function dashboard(Request $request) { $stat = new \Stdclass(); $stat->num_ads = Ad::count(); $stat->num_promo_ads = Ad::where('ad_promo', 1)->count(); $stat->users = User::count(); $stat->reports = AdReport::count(); //get last 10 days ads $ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_date = []; if (!empty($ads_by_date)) { $stat->ads_by_date = array_reverse($ads_by_date); } //get last 10 promo days ads $promo_ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->where('ad_promo', 1)->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->promo_ads_by_date = []; if (!empty($promo_ads_by_date)) { $stat->promo_ads_by_date = array_reverse($promo_ads_by_date); } //get last 10 months ads $ads_by_month = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_month = []; if (!empty($ads_by_month)) { $stat->ads_by_month = array_reverse($ads_by_month); } //get last 10 years ads $ads_by_year = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_year = []; if (!empty($ads_by_year)) { $stat->ads_by_year = array_reverse($ads_by_year); } return view('admin.dashboard.dashboard', ['stat' => $stat]); }
public function getAllHierarhy($_parent_id = null, $_level = 0, $_active = 1) { $cache_key = __CLASS__ . '_' . __LINE__ . '_' . md5(config('dc.site_domain') . serialize(func_get_args())); $ret = Cache::get($cache_key, []); if (empty($ret)) { $_level++; $lquery = $this->where('location_parent_id', $_parent_id)->with('children')->orderBy('location_ord', 'asc')->orderBy('location_name', 'asc'); if ($_active) { $lquery->where('location_active', '=', 1); } $locationCollection = $lquery->get(); if (!empty($locationCollection)) { foreach ($locationCollection as $k => $v) { $ret[$v->location_id] = array('lid' => $v->location_id, 'title' => $v->location_name, 'slug' => $v->location_slug, 'active' => $v->location_active, 'post_code' => $v->location_post_code, 'ord' => $v->location_ord, 'level' => $_level, 'ad_count' => Ad::where('location_id', $v->location_id)->count()); if (!empty($v->location_post_code)) { $ret[$v->location_id]['title'] = $v->location_name . ' [ZIP:' . $v->location_post_code . ']'; } if ($v->children->count() > 0) { $ret[$v->location_id]['c'] = $this->getAllHierarhy($v->location_id, $_level, $_active); } } Cache::put($cache_key, $ret, config('dc.cache_expire')); } } return $ret; }
public function edit($id) { $placement = Ad_Web::find($id); $ads = Ad::orderby('nombre')->lists('nombre', 'id'); $webs = Web::orderBy('url')->lists('url', 'id'); return view('admin.publisher.edit', compact('placement', 'ads', 'webs')); }
public function run() { DB::table('ads')->delete(); $imgs = array('2015-06-09-06-45-14-465.png', '2015-06-09-11-42-59-111.png', '2015-06-09-11-43-32-544.png', '2015-06-09-12-02-11-636.png', '2015-06-09-12-02-26-650.png', '2015-06-09-12-02-42-669.png', '2015-06-09-12-03-02-88.png', '2015-06-09-12-03-18-933.gif'); for ($i = 1; $i <= 5000; $i++) { Ad::create(['uid' => $i % 200 + 1, 'title' => 'Title (' . $i . ')', 'type' => $i % 2, 'img_path' => $imgs[$i % 8], 'content' => 'Content (' . $i . ')', 'uname' => 'Uname (' . ($i % 200 + 1) . ')', 'longitude' => 113.398238 + ($i % 200 + 1) / 5000, 'latitude' => 23.06668 + ($i % 200 + 1) / 5000, 'begin_at' => '2015-07-' . ($i % 31 + 1), 'end_at' => '2015-08-' . ($i % 31 + 1), 'status' => $i % 4, 'page_view' => 0, 'page_click' => 0]); } }
public function ads() { if (Auth::check()) { $ads = Ad::where('author_id', Auth::user()->id)->orderBy('created_at', 'desc')->paginate(30); return view('profile.ads', ['ads' => $ads]); } else { return redirect('/'); } }
public function index(Request $request) { //get info for this payment $payTypeInfo = Pay::find(Pay::PAY_TYPE_MOBIO); //calc promo period $promoUntilDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $payTypeInfo->pay_promo_period, date('Y'))); //get incoming params $message = isset($request->message) ? $request->message : null; $item = isset($request->item) ? $request->item : null; $fromnum = isset($request->fromnum) ? $request->fromnum : null; $extid = isset($request->extid) ? $request->extid : null; $servID = isset($request->servID) ? $request->servID : null; //check if ping is comming from allowed ips $mobio_remote_address = explode(',', $payTypeInfo->pay_allowed_ip); if (in_array($request->ip(), $mobio_remote_address)) { $sms_reply = trans('payment_mobio.There is error, please contact us.'); $item = trim($item); if (!empty($item)) { try { $pay_type = mb_strtolower(mb_substr($item, 0, 1)); //make ad vip if ($pay_type == 'a') { $ad_id = mb_substr($item, 1); $adInfo = Ad::find($ad_id); if (!empty($adInfo)) { //update ad $adInfo->ad_promo = 1; $adInfo->ad_promo_until = $promoUntilDate; $adInfo->save(); //add money to wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_mobio.Payment via Mobio SMS')]; Wallet::create($wallet_data); //subtract money from wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => -$payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate])]; Wallet::create($wallet_data); $sms_reply = trans('payment_mobio.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate]); Cache::flush(); } } //add money to wallet if ($pay_type == 'w') { $user_id = mb_substr($item, 1); $userInfo = User::find($user_id); if (!empty($userInfo)) { //save money to wallet $wallet_data = ['user_id' => $userInfo->user_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_mobio.Add Money to Wallet via Mobio SMS')]; Wallet::create($wallet_data); $sms_reply = trans('payment_mobio.You have added :money to your wallet.', ['money' => number_format($payTypeInfo->pay_sum, 2) . config('dc.site_price_sign')]); Cache::flush(); } } } catch (\Exception $e) { } } file_get_contents("http://mobio.bg/paynotify/pnsendsms.php?servID={$servID}&tonum={$fromnum}&extid={$extid}&message=" . urlencode($sms_reply)); } }
public function index(Request $request) { $sms_reply = trans('payment_fortumo.There is error, please contact us.'); //get info for this payment $payTypeInfo = Pay::find(Pay::PAY_TYPE_FORTUMO); //calc promo period $promoUntilDate = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + $payTypeInfo->pay_promo_period, date('Y'))); //get incoming params $message = isset($request->message) ? $request->message : null; $status = isset($request->status) ? $request->status : null; $billing_type = isset($request->billing_type) ? $request->billing_type : null; //check if ping is comming from allowed ips $fortumo_remote_address = explode(',', $payTypeInfo->pay_allowed_ip); if (in_array($request->ip(), $fortumo_remote_address) && $this->check_signature($request->all(), $payTypeInfo->pay_secret)) { $message = trim($message); if (!empty($message) && (preg_match("/OK/i", $status) || preg_match("/MO/i", $billing_type) && preg_match("/pending/i", $status))) { try { $pay_type = mb_strtolower(mb_substr($message, 0, 1)); //make ad vip if ($pay_type == 'a') { $ad_id = mb_substr($message, 1); $adInfo = Ad::find($ad_id); if (!empty($adInfo)) { //update ad $adInfo->ad_promo = 1; $adInfo->ad_promo_until = $promoUntilDate; $adInfo->save(); //add money to wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Payment via Fortumo SMS')]; Wallet::create($wallet_data); //subtract money from wallet $wallet_data = ['user_id' => $adInfo->user_id, 'ad_id' => $ad_id, 'sum' => -$payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate])]; Wallet::create($wallet_data); $sms_reply = trans('payment_fortumo.Your ad #:ad_id is Promo Until :date.', ['ad_id' => $ad_id, 'date' => $promoUntilDate]); Cache::flush(); } } //add money to wallet if ($pay_type == 'w') { $user_id = mb_substr($message, 1); $userInfo = User::find($user_id); if (!empty($userInfo)) { //save money to wallet $wallet_data = ['user_id' => $userInfo->user_id, 'sum' => $payTypeInfo->pay_sum, 'wallet_date' => date('Y-m-d H:i:s'), 'wallet_description' => trans('payment_fortumo.Add Money to Wallet via Fortumo SMS')]; Wallet::create($wallet_data); $sms_reply = trans('payment_fortumo.You have added :money to your wallet.', ['money' => number_format($payTypeInfo->pay_sum, 2) . config('dc.site_price_sign')]); Cache::flush(); } } } catch (\Exception $e) { } } } echo $sms_reply; }
public function update($id, $status) { if (empty($id)) { return redirect('/admin/ads'); } $ads = Ad::find($id); if (empty($ads)) { return redirect('/admin/ads'); } $ads->status = $status; $ads->save(); return redirect('/admin/ads'); }
/** * Display the home page. */ public function index() { $carousel_news = Article::select('id', 'title', 'page_image')->where('is_checked', true)->where('is_carousel', true)->published()->get(); $latest_news = Article::select('id', 'title', 'intro', 'page_image')->where('is_checked', true)->published()->orderBy('published_at', 'desc')->take(4)->get(); $ads = Ad::select('url', 'name', 'image_path')->orderBy('created_at', 'desc')->take(2)->get(); // get the index article $tags = Tag::select('id', 'name')->where('show_index', true)->get(); $index_articles = array(); foreach ($tags as $tag) { $tag['articles'] = $tag->articles()->select('article_id', 'title', 'intro', 'page_image')->where('is_checked', true)->published()->orderBy('published_at', 'desc')->take(3)->get(); $index_articles[] = $tag; } return view('front.index')->with('carousel_news', $carousel_news)->with('latest_news', $latest_news)->with('ads', $ads)->with('index_articles', $index_articles); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(AdFilters $filters, $slug = null, $make_slug = null, $model_slug = null) { if (Request::has('category')) { $getParameters = '?'; foreach (Request::except(['category', 'make', 'model']) as $key => $value) { $getParameters .= $value == '' ? '' : "{$key}={$value}&"; } $getParameters = substr($getParameters, 0, -1); $redirectPath = '/category/' . Request::input('category'); if (Request::has('make') && Request::input('make') != 'any') { $redirectPath .= '/' . Request::input('make'); if (Request::has('model') && Request::input('model') != 'any') { $redirectPath .= '/' . Request::input('model'); } } return redirect($redirectPath . $getParameters); } $builder = Ad::filter($filters)->orderBy('created_at', 'desc')->with(['auto_models', 'favorite']); if ($slug) { $category = Category::where('slug', $slug)->firstOrFail(); if ($category->parent_id) { $builder->where('category_id', $category->id); } else { $categories_ids = $category->childs()->select('id')->get(); $builder->whereIn('category_id', $categories_ids); } if ($make_slug) { if (!$model_slug) { $make_id = AutoModel::where('slug', $make_slug)->select('id')->firstOrFail()->id; $builder->whereHas('auto_models', function ($query) use($make_id) { $query->where('auto_models.make_id', $make_id); }); } else { $model_id = AutoModel::where('slug', $model_slug)->select('id')->firstOrFail()->id; $builder->whereHas('auto_models', function ($query) use($model_id) { $query->where('auto_models.id', $model_id); }); } } } $ads = $builder->paginate(30)->setPath(Request::url())->appends(Request::except('page')); // dd($slug, Category::where('slug', $slug)->first()); $data = ['ads' => $ads, 'regions' => Region::getAllWithCities()]; if (isset($category)) { $data['category'] = $category; $data['title'] = $category->name; } return view('mainpage', $data); }
/** * Get the ads for search based on type, (longitude, latitude, region) or keyword. * * @return Json */ public function getSearchAds(Request $request) { $uid = $request->input('uid'); $type = $request->input('type'); $region = $request->input('region', 0.2); $lng = $request->input('lng'); $lat = $request->input('lat'); $keyword = $request->input('keyword'); $earthRadius = 6378.138; $dlng = 2 * asin(sin($region / (2 * $earthRadius)) / cos(deg2rad($lat))); $dlng = rad2deg($dlng); $dlat = $region / $earthRadius; $dlat = rad2deg($dlat); //return 'region='.$region.', lnt='.$lng.', lat='.$lat.', dlng='.$dlng.', dlat='.$dlat; if ($uid) { $ads = Ad::where('uid', $uid); $ads = $ads->where('status', 1)->paginate(10); return $ads->toJson(); } else { if ($type) { $ads = Ad::where('type', $type); if ($lng && $lat) { $ads = $ads->whereBetween('longitude', [$lng - $dlng, $lng + $dlng])->whereBetween('latitude', [$lat - $dlat, $lat + $dlat]); } if ($keyword) { $ads = $ads->where('title', 'like', '%' . $keyword . '%'); } $ads = $ads->where('status', 1)->paginate(10); return $ads->toJson(); } else { if ($lng && $lat) { $ads = Ad::whereBetween('longitude', [$lng - $dlng, $lng + $dlng])->whereBetween('latitude', [$lat - $dlat, $lat + $dlat]); if ($keyword) { $ads = $ads->where('title', 'like', '%' . $keyword . '%'); } $ads = $ads->where('status', 1)->paginate(10); return $ads->toJson(); } else { if ($keyword) { $ads = Ad::where('title', 'like', '%' . $keyword . '%'); $ads = $ads->where('status', 1)->paginate(10); return $ads->toJson(); } } } } }
public function postBatch($act = 'update') { $result = false; switch ($act) { case 'delete': $ids = \Request::input('ids'); $idsArr = explode(',', $ids); $result = Ad::whereIn('id', $idsArr)->delete(); break; } $msg = []; if ($result) { $msg['status'] = 'success'; } else { $msg['status'] = 'failed'; } return response(json_encode($msg))->header('Content-Type', 'application/json'); }
public function getAllHierarhy($_parent_id = null, $_level = 0, $_active = 1) { $ret = array(); $_level++; $query = $this->where('category_parent_id', $_parent_id)->with('children')->orderBy('category_ord', 'asc'); if ($_active) { $query->where('category_active', '=', 1); } $categoryCollection = $query->get(); if (!empty($categoryCollection)) { foreach ($categoryCollection as $k => $v) { $ret[$v->category_id] = array('cid' => $v->category_id, 'title' => $v->category_title, 'level' => $_level, 'category_type' => $v->category_type, 'ord' => $v->category_ord, 'slug' => $v->category_slug, 'active' => $v->category_active, 'ad_count' => Ad::where('category_id', $v->category_id)->count()); if ($v->children->count() > 0) { $ret[$v->category_id]['c'] = $this->getAllHierarhy($v->category_id, $_level, $_active); } } } return $ret; }
public function parse(Request $request) { $parsed = json_decode($request['json'], true); foreach ($parsed as $key => $value) { unset($parsed[$key]['images']); unset($parsed[$key]['href']); $city = City::where('name', $value['city_id'])->first(); if ($city === null) { unset($parsed[$key]); continue; } $parsed[$key]['category_id'] = 5; $parsed[$key]['city_id'] = $city->id; $parsed[$key]['created_at'] = Carbon::now()->subMinutes(rand(1, 59)); $parsed[$key]['updated_at'] = Carbon::now()->subMinutes(rand(1, 59)); } // dd($parsed); Ad::insert($parsed); return response('OK', 200); }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { /*$schedule->command('inspire') ->hourly();*/ $schedule->call(function () { $feeds = ['http://www.kijiji.ca/rss-srp-bikes/kitchener-waterloo/c644l1700212', 'http://www.kijiji.ca/rss-srp-kitchener-waterloo/l1700212?ad=offering&price-type=free']; foreach ($feeds as $feed) { \Log::info('Refreshing feeds: ' . $feed); /*$feed_key = md5($feed); \Log::info('Parsing feed' . $feed_key); if (Cache::has($feed_key)){ $feed = Cache::get($feed_key); echo "Cached<br>"; }else{ $feed = Feeds::make($feed); Cache::put($feed_key, $feed, 9); echo "NOT cached<br>"; }*/ $feed = Feeds::make($feed); $data = array('title' => $feed->get_title(), 'permalink' => $feed->get_permalink(), 'items' => $feed->get_items()); $parser = new HtmlDomParser(); foreach ($data['items'] as $item) { $tokens = explode('/', $item->get_link()); $id = end($tokens); if (!Ad::find($id)) { $price = ''; $title = $item->get_title(); $description = $item->get_description() . "<br/>=================<br/>"; $link = $item->get_link(); $html = $parser->file_get_html($link); foreach ($html->find('span[itemprop=price]') as $span) { $price = $span->plaintext; } foreach ($html->find('div[id=ImageThumbnails] img') as $img) { $src = str_replace('$_14', '$_27', $img->src); $description .= "<img src='{$src}'> <br/>"; } $ad = new Ad(); $ad->id = $id; $ad->title = $title; $ad->description = $description; $ad->price = $price; $ad->link = $link; $ad->save(); \Log::info("Added " . $id . " {$price}"); } else { #\Log::info("Item already on database " . $id); } } } })->everyFiveMinutes(); /*$schedule->call(function () { $params = ['feed' => \Crypt::encrypt('http://www.kijiji.ca/rss-srp-bikes/kitchener-waterloo/c644l1700212')]; $request = Request::create('parsefeed', 'GET', $params); \Log::info('Refreshing feeds: ' . $params['feed']); return \Route::dispatch($request)->getContent(); })->everyMinute();*/ $schedule->call(function () { \Log::info('Checking for new ads'); $ads = Ad::whereEmailed(false)->get(); foreach ($ads as $ad) { $data['ad'] = $ad; $blocked_keywords = "[scrap|removal|membership]"; if (preg_match($blocked_keywords, strtolower($ad->title)) == 0) { \Log::info('Emailing new ad: ' . $ad->title); $ret = \Mail::send(['html' => 'emails.ad'], $data, function ($message) use($data) { $message->to('*****@*****.**', 'Herbert Balagtas')->subject('Jijiki Alert: ' . $data['ad']->price . ' - ' . html_entity_decode(html_entity_decode($data['ad']->title))); $message->from('*****@*****.**', 'Jijiki Alert'); }); } else { \Log::info('Skipping spam ad: ' . $ad->title); } $ad->emailed = true; $ad->save(); } })->everyTenMinutes(); }
public function ReportsDate(Request $request) { if ($request->ajax()) { $date = date('Y-m-d', strtotime($request->input('date'))); $todate = date('Y-m-d', strtotime($request->input('todate'))); $idad = $request->input('ad'); $idweb = $request->input('web'); if ($idad == 0) { if ($idweb == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { if ($request->ajax()) { if ($idad == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { $ad = Web::find($idweb); $reports = Report::ReportTime($date, $todate, $ad->id); return response()->json(["web" => $reports]); } } } } else { if ($idad == 'all' || $idweb == 'all') { if ($request->ajax()) { $reports = Report::TimeReport($date, $todate); return response()->json(["web" => $reports]); } } else { if ($request->ajax()) { $ad = Ad::find($idad); $web = Web::find($idweb); $reports = Report::TimeReportComplete($date, $todate, $ad->id, $web->id); return response()->json(["web" => $reports]); } } } } }
public static function removeFromCaches($job_id) { $jobCache = self::getInfo($job_id); if (!empty($jobCache)) { self::removeJobFromRecentCache($job_id); if (!empty($jobCache['JobDmaCode'])) { self::removeJobFromDmaCache($jobCache['JobDmaCode'], $job_id); } // remove from ads Ad::deleteAdDetailsCache($job_id); if (!empty($jobCache['JobKeywords'])) { $keywords = explode(',', $jobCache['JobKeywords']); foreach ($keywords as $kw) { Keyword::removeJobFromKeywordCache($kw, $job_id); } } if (!empty($jobCache['JobCompanyStrId'])) { Company::removeJobFromCompanyCache($jobCache['JobCompanyStrId'], $job_id); } self::removeCache($job_id); } }
public function refresh($id) { if (Auth::check()) { $ad = Ad::whereId($id)->first(); $leftToRefresh = 3 - floor((time() - strtotime($ad->created_at)) / 86400); if ($ad->author_id == Auth::user()->id && $leftToRefresh <= 0) { $ad->created_at = date('Y-m-d G:i:s'); $ad->save(); return 1; } } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function remove($id) { if (Auth::check()) { $comment = Comment::whereId($id)->first(); if ($comment === null) { $ad_id = Request::input('ad'); } else { $ad_id = $comment->ad_id; $user_id = Auth::user()->id; if ($user_id == $comment->author_id || $user_id == $comment->ad->author->id) { $comment->delete(); } } return view('sub.comments', ['ad' => Ad::getById($ad_id), 'comments' => Comment::getByAdId($ad_id)]); } }
public function deletemainimg(Request $request) { $id = 0; if (isset($request->id)) { $id = $request->id; } //delete if (!empty($id)) { $ad = Ad::where('ad_id', $id)->first(); if (!empty($ad)) { //delete images if (!empty($ad->ad_pic)) { @unlink(public_path('uf/adata/') . '740_' . $ad->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $ad->ad_pic); } $ad->ad_pic = ''; $ad->save(); } //clear cache, set message, redirect to list Cache::flush(); return redirect(url('admin/ad/edit/' . $id)); } return redirect(url('admin/ad/edit/' . $id)); }
/** * Determine if the given ad can be refreshed by the user. * * @param \App\User $user * @param \App\Ad $ad * @return bool */ public function refresh(User $user, Ad $ad) { return $user->id === $ad->author_id && $ad->getDaysToRefresh() <= 0; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Ad::destroy($id); }
public function delete(Request $request) { //users to be deleted $data = []; //check for single delete if (isset($request->id)) { $data[] = $request->id; } //check for mass delete if no single delete if (empty($data)) { $data = $request->input('user_id'); } //delete if (!empty($data)) { foreach ($data as $k => $v) { $u = User::find($v); //get all user ads $userAds = Ad::where('user_id', $u->user_id)->get(); if (!$userAds->isEmpty()) { foreach ($userAds as $ka => $va) { //delete ads images $more_pics = AdPic::where('ad_id', $va->ad_id)->get(); if (!$more_pics->isEmpty()) { foreach ($more_pics as $km => $vm) { @unlink(public_path('uf/adata/') . '740_' . $vm->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $vm->ad_pic); $vm->delete(); } } if (!empty($va->ad_pic)) { @unlink(public_path('uf/adata/') . '740_' . $va->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $va->ad_pic); } $va->delete(); } } //check for avatar and delete if any if (!empty($u->avatar)) { @unlink(public_path('uf/udata/') . '100_' . $u->avatar); } $u->delete(); } //clear cache, set message, redirect to list Cache::flush(); session()->flash('message', trans('admin_common.User and All User Ads Deleted')); return redirect(url('admin/user')); } //nothing for deletion set message and redirect session()->flash('message', trans('admin_common.Nothing for deletion')); return redirect(url('admin/user')); }
public function getAd(Request $request) { $response = []; if (empty($request->get('dma'))) { $response = \App\AdGeneral::get(1); } else { $dma = trim(strtolower($request->get('dma'))); $response = \App\Ad::get($dma); if (empty($response)) { $response = \App\AdGeneral::get(1); } } return response()->json($response)->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'GET, POST')->setCallback($request->input('callback')); }
/** * Run the database seeds. * * @return void */ public function run() { define('THIS_MANY_ADS', \App\Constants::first()->n_ad_seeds); $faker = Faker\Factory::create('es_ES'); $n_house_categories = DB::table('category_house')->count(); $n_country_house_categories = DB::table('category_country_house')->count(); $n_business_categories = DB::table('category_business')->count(); $n_land_categories = DB::table('category_land')->count(); $n_lodging_categories = DB::table('category_lodging')->count(); $n_room_categories = DB::table('category_room')->count(); $n_energy_certification_options = DB::table('energy_certification')->count(); $n_business_distribution_options = DB::table('business_distribution')->count(); $n_business_facade_options = DB::table('business_facade')->count(); $n_business_location_options = DB::table('business_location')->count(); $n_current_tenants_gender_options = DB::table('current_tenants_gender')->count(); $n_garage_capacity_options = DB::table('garage_capacity')->count(); $n_nearest_town_distance_options = DB::table('nearest_town_distance')->count(); $n_office_distribution_options = DB::table('office_distribution')->count(); $n_payment_day_options = DB::table('payment_day')->count(); $n_surroundings_options = DB::table('surroundings')->count(); $n_tenant_gender_options = DB::table('tenant_gender')->count(); $n_tenant_min_stay_options = DB::table('tenant_min_stay')->count(); $n_tenant_occupation_options = DB::table('tenant_occupation')->count(); $n_tenant_sexual_orientation_options = DB::table('tenant_sexual_orientation')->count(); $performances = ['75', '100', '125', '150', '175', '200', '225', '250']; $certs = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; $blocks = ['A', 'B', 'C', 'D', 'E']; $doors = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', 'Puerta única', 'Izquierda', 'Derecha', 'Exterior', 'Interior', 'Centro', 'Exterior izquierda', 'Exterior derecha', 'Interior izquierda', 'Interior derecha', 'Centro izquierda', 'Centro derecha']; $floors = ['Planta 1º', 'Planta 2º', 'Planta 3º', 'Planta 4º', 'Planta 5º', 'Planta 6º', 'Planta 7º', 'Planta 8º', 'Planta 9º', 'Planta 10º', 'Planta 11º', 'Planta 12º', 'Planta 13º', 'Planta 14º', 'Planta 15º', 'Planta 16º', 'Planta 17º', 'Planta 18º', 'Planta 19º', 'Planta 20º', 'Planta 21º', 'Planta 22º', 'Planta 23º', 'Planta 24º', 'Planta 25º', 'Planta 26º', 'Sótano', 'Semi-sótano', 'Bajo', 'Entreplanta', 'Por debajo de la planta baja (-2)', 'Por debajo de la planta baja (-1)']; $activities = ['Tienda de ropa', 'Frutería', 'Panadería', 'Taller mecánico', 'Bar', 'Restaurante', 'Carnicería', 'Gestión de residuos industriales', 'Copistería', 'Fábrica de papel', 'Acerería', 'Alfarería', 'Fábrica de cemento', 'Fábrica de mezcla bituminosa', 'Tienda de respuestos']; $deposits = ['1 mes', '2 meses', '3 meses', '4 meses', '5 meses', '6 meses o más']; for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentHouse = \App\RentHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_house_id' => mt_rand(1, $n_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'has_equipped_kitchen' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_house'; $newAd->local_id = $newRentHouse->id; $newAd->save(); $this->command->info('Seeded Rent House (id: ' . $newRentHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellHouse = \App\SellHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_house_id' => mt_rand(1, $n_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_house'; $newAd->local_id = $newSellHouse->id; $newAd->save(); $this->command->info('Seeded Sell House (id: ' . $newSellHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(300, 2400); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellCountryHouse = \App\SellCountryHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_country_house_id' => mt_rand(1, $n_country_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_country_house'; $newAd->local_id = $newSellCountryHouse->id; $newAd->save(); $this->command->info('Seeded Sell Country House (id: ' . $newSellCountryHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(300, 2400); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentCountryHouse = \App\RentCountryHouse::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_country_house_id' => mt_rand(1, $n_country_house_categories), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_land' => $area_land, 'n_floors' => mt_rand(1, 4), 'n_bedrooms' => mt_rand(1, 4), 'n_bathrooms' => mt_rand(1, 4), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_country_house'; $newAd->local_id = $newRentCountryHouse->id; $newAd->save(); $this->command->info('Seeded Rent Country House (id: ' . $newRentCountryHouse->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newRentOffice = \App\RentOffice::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_min_for_sale' => $area_min_for_sale, 'n_floors' => mt_rand(1, 4), 'has_offices_only' => mt_rand(0, 1), 'office_distribution_id' => mt_rand(1, $n_office_distribution_options), 'n_restrooms' => mt_rand(1, 8), 'has_bathrooms' => mt_rand(0, 1), 'has_fire_detectors' => mt_rand(0, 1), 'has_fire_extinguishers' => mt_rand(0, 1), 'has_fire_sprinklers' => mt_rand(0, 1), 'has_fireproof_doors' => mt_rand(0, 1), 'has_emergency_lights' => mt_rand(0, 1), 'has_doorman' => mt_rand(0, 1), 'has_air_conditioning_preinstallation' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_hot_water' => mt_rand(0, 1), 'has_kitchen' => mt_rand(0, 1), 'has_archive' => mt_rand(0, 1), 'has_double_windows' => mt_rand(0, 1), 'has_suspended_ceiling' => mt_rand(0, 1), 'has_suspended_floor' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'has_bathrooms_inside' => mt_rand(0, 1), 'is_exterior' => mt_rand(0, 1), 'n_elevators' => mt_rand(1, 8), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'n_parking_spaces' => mt_rand(10, 50), 'has_steel_door' => mt_rand(0, 1), 'has_security_system' => mt_rand(0, 1), 'has_access_control' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_office'; $newAd->local_id = $newRentOffice->id; $newAd->save(); $this->command->info('Seeded Rent Office (id: ' . $newRentOffice->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newSellOffice = \App\SellOffice::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'area_min_for_sale' => $area_min_for_sale, 'n_floors' => mt_rand(1, 4), 'has_offices_only' => mt_rand(0, 1), 'office_distribution_id' => mt_rand(1, $n_office_distribution_options), 'n_restrooms' => mt_rand(1, 8), 'has_bathrooms' => mt_rand(0, 1), 'has_fire_detectors' => mt_rand(0, 1), 'has_fire_extinguishers' => mt_rand(0, 1), 'has_fire_sprinklers' => mt_rand(0, 1), 'has_fireproof_doors' => mt_rand(0, 1), 'has_emergency_lights' => mt_rand(0, 1), 'has_doorman' => mt_rand(0, 1), 'has_air_conditioning_preinstallation' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_hot_water' => mt_rand(0, 1), 'has_kitchen' => mt_rand(0, 1), 'has_archive' => mt_rand(0, 1), 'has_double_windows' => mt_rand(0, 1), 'has_suspended_ceiling' => mt_rand(0, 1), 'has_suspended_floor' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'has_bathrooms_inside' => mt_rand(0, 1), 'is_exterior' => mt_rand(0, 1), 'n_elevators' => mt_rand(1, 8), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'n_parking_spaces' => mt_rand(10, 50), 'has_steel_door' => mt_rand(0, 1), 'has_security_system' => mt_rand(0, 1), 'has_access_control' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_office'; $newAd->local_id = $newSellOffice->id; $newAd->save(); $this->command->info('Seeded Sell Office (id: ' . $newSellOffice->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newRentBusiness = \App\RentBusiness::create(['ad_id' => $newAd->id, 'price' => $price, 'is_transfer' => mt_rand(0, 1), 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'category_business_id' => mt_rand(1, $n_business_categories), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'business_distribution_id' => mt_rand(1, $n_business_distribution_options), 'business_facade_id' => mt_rand(1, $n_business_facade_options), 'n_shop_windows' => mt_rand(1, 4), 'business_location_id' => mt_rand(1, $n_business_location_options), 'n_floors' => mt_rand(1, 3), 'n_restrooms' => mt_rand(1, 4), 'last_activity' => $activities[array_rand($activities)], 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'has_archive' => mt_rand(0, 1), 'has_smoke_extractor' => mt_rand(0, 1), 'has_fully_equipped_kitchen' => mt_rand(0, 1), 'has_steel_door' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'is_corner_located' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_business'; $newAd->local_id = $newRentBusiness->id; $newAd->save(); $this->command->info('Seeded Rent Business (id: ' . $newRentBusiness->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $newAd = App\Ad::create(); $newSellBusiness = \App\SellBusiness::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'category_business_id' => mt_rand(1, $n_business_categories), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'business_distribution_id' => mt_rand(1, $n_business_distribution_options), 'business_facade_id' => mt_rand(1, $n_business_facade_options), 'n_shop_windows' => mt_rand(1, 4), 'business_location_id' => mt_rand(1, $n_business_location_options), 'n_floors' => mt_rand(1, 3), 'n_restrooms' => mt_rand(1, 4), 'last_activity' => $activities[array_rand($activities)], 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'has_archive' => mt_rand(0, 1), 'has_smoke_extractor' => mt_rand(0, 1), 'has_fully_equipped_kitchen' => mt_rand(0, 1), 'has_steel_door' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'is_corner_located' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_business'; $newAd->local_id = $newSellBusiness->id; $newAd->save(); $this->command->info('Seeded Sell Business (id: ' . $newSellBusiness->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(10000, 100000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 100); $newAd = App\Ad::create(); $newSellGarage = \App\SellGarage::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'garage_capacity_id' => mt_rand(1, $n_garage_capacity_options), 'is_covered' => mt_rand(0, 1), 'has_automatic_door' => mt_rand(0, 1), 'has_lift' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'has_security_guard' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_garage'; $newAd->local_id = $newSellGarage->id; $newAd->save(); $this->command->info('Seeded Sell Garage (id: ' . $newSellGarage->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100, 1000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $newAd = App\Ad::create(); $newRentGarage = \App\RentGarage::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'garage_capacity_id' => mt_rand(1, $n_garage_capacity_options), 'is_covered' => mt_rand(0, 1), 'has_automatic_door' => mt_rand(0, 1), 'has_lift' => mt_rand(0, 1), 'has_alarm' => mt_rand(0, 1), 'has_security_camera' => mt_rand(0, 1), 'has_security_guard' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_garage'; $newAd->local_id = $newRentGarage->id; $newAd->save(); $this->command->info('Seeded Rent Garage (id: ' . $newRentGarage->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(50000, 500000); $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10) * $area_usable; $newAd = App\Ad::create(); $newSellLand = \App\SellLand::create(['ad_id' => $newAd->id, 'price' => $price, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_land_id' => mt_rand(1, $n_land_categories), 'area_total' => $area_land, 'area_building_land' => $area_constructed, 'area_min_for_sale' => $area_min_for_sale, 'is_classified_residential_block' => mt_rand(0, 1), 'is_classified_residential_house' => mt_rand(0, 1), 'is_classified_office' => mt_rand(0, 1), 'is_classified_commercial' => mt_rand(0, 1), 'is_classified_hotel' => mt_rand(0, 1), 'is_classified_industrial' => mt_rand(0, 1), 'is_classified_public_service' => mt_rand(0, 1), 'is_classified_others' => mt_rand(0, 1), 'max_floors_allowed' => mt_rand(0, 5) ? mt_rand(1, 3) : mt_rand(1, 30), 'has_road_access' => mt_rand(0, 1), 'nearest_town_distance_id' => mt_rand(1, $n_nearest_town_distance_options), 'has_water' => mt_rand(0, 1), 'has_electricity' => mt_rand(0, 1), 'has_sewer_system' => mt_rand(0, 1), 'has_natural_gas' => mt_rand(0, 1), 'has_street_lighting' => mt_rand(0, 1), 'has_sidewalks' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_land'; $newAd->local_id = $newSellLand->id; $newAd->save(); $this->command->info('Seeded Sell Land (id: ' . $newSellLand->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(200, 5000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $area_min_for_sale = intval(mt_rand(5, 10) / 10 * $area_usable); $newAd = App\Ad::create(); $newRentLand = \App\RentLand::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_land_id' => mt_rand(1, $n_land_categories), 'area_total' => $area_land, 'area_building_land' => $area_constructed, 'area_min_for_sale' => $area_min_for_sale, 'is_classified_residential_block' => mt_rand(0, 1), 'is_classified_residential_house' => mt_rand(0, 1), 'is_classified_office' => mt_rand(0, 1), 'is_classified_commercial' => mt_rand(0, 1), 'is_classified_hotel' => mt_rand(0, 1), 'is_classified_industrial' => mt_rand(0, 1), 'is_classified_public_service' => mt_rand(0, 1), 'is_classified_others' => mt_rand(0, 1), 'max_floors_allowed' => mt_rand(0, 5) ? mt_rand(1, 3) : mt_rand(1, 30), 'has_road_access' => mt_rand(0, 1), 'nearest_town_distance_id' => mt_rand(1, $n_nearest_town_distance_options), 'has_water' => mt_rand(0, 1), 'has_electricity' => mt_rand(0, 1), 'has_sewer_system' => mt_rand(0, 1), 'has_natural_gas' => mt_rand(0, 1), 'has_street_lighting' => mt_rand(0, 1), 'has_sidewalks' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_land'; $newAd->local_id = $newRentLand->id; $newAd->save(); $this->command->info('Seeded Rent Land (id: ' . $newRentLand->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(600, 2000); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newRentApartment = \App\RentApartment::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'is_regular' => mt_rand(0, 1), 'is_penthouse' => mt_rand(0, 1), 'is_duplex' => mt_rand(0, 1), 'is_studio' => mt_rand(0, 1), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'n_bedrooms' => mt_rand(1, 5), 'n_bathrooms' => mt_rand(1, 3), 'is_exterior' => mt_rand(0, 1), 'has_equipped_kitchen' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_apartment'; $newAd->local_id = $newRentApartment->id; $newAd->save(); $this->command->info('Seeded Rent Apartment (id: ' . $newRentApartment->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(100000, 1000000); $community_cost = mt_rand(0, 5) ? null : mt_rand(10, 300); $energy_cert_id = mt_rand(1, $n_energy_certification_options); $energy_cert_name = \App\EnergyCertification::find($energy_cert_id)->name; $energy_performance = in_array($energy_cert_name, $certs) ? $performances[array_rand($performances)] : null; $area_land = mt_rand(100, 800); $area_constructed = intval(0.6 * $area_land); $area_usable = intval(0.8 * $area_constructed); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $is_new_development = mt_rand(0, 1); $is_new_development_finished = $is_new_development ? mt_rand(0, 1) : 0; $newAd = App\Ad::create(); $newSellApartment = \App\SellApartment::create(['ad_id' => $newAd->id, 'price' => $price, 'community_cost' => $community_cost, 'is_bank_agency' => mt_rand(0, 1), 'is_state_subsidized' => mt_rand(0, 1), 'is_new_development' => $is_new_development, 'is_new_development_finished' => $is_new_development_finished, 'is_rent_to_own' => mt_rand(0, 1), 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'is_regular' => mt_rand(0, 1), 'is_penthouse' => mt_rand(0, 1), 'is_duplex' => mt_rand(0, 1), 'is_studio' => mt_rand(0, 1), 'needs_restoration' => mt_rand(0, 1), 'area_constructed' => $area_constructed, 'area_usable' => $area_usable, 'n_bedrooms' => mt_rand(1, 5), 'n_bathrooms' => mt_rand(1, 3), 'is_exterior' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'energy_certification_id' => $energy_cert_id, 'energy_performance' => $energy_performance, 'faces_north' => mt_rand(0, 1), 'faces_south' => mt_rand(0, 1), 'faces_east' => mt_rand(0, 1), 'faces_west' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_box_room' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_swimming_pool' => mt_rand(0, 1), 'has_garden' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'sell_apartment'; $newAd->local_id = $newSellApartment->id; $newAd->save(); $this->command->info('Seeded Sell Apartment (id: ' . $newSellApartment->id . ')'); } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $n_d_b = mt_rand(0, 2); $n_1_b = mt_rand(0, 2); $n_2_b = mt_rand(0, 2); $n_3_b = mt_rand(0, 1); $n_4_b = mt_rand(0, 1); $min_capacity = $n_d_b * 2 + $n_1_b + $n_2_b * 2 + $n_3_b * 3 + $n_4_b * 4; $n_sb = mt_rand(0, 1); $n_d_sb = mt_rand(0, 1); $n_eb = mt_rand(0, 1); $max_capacity = $min_capacity + $n_sb + $n_d_sb * 2 + $n_eb; $payment_day = mt_rand(1, $n_payment_day_options); $days_before = \App\OptionPaymentDay::find($payment_day)->pluck('name') == 'Días antes de la entrada' ? mt_rand(1, 30) : null; $has_booking = mt_rand(0, 2); $has_deposit = mt_rand(0, 2); $has_cleaning = mt_rand(0, 1); if ($has_booking == 1) { $booking = mt_rand(1, 100); } elseif ($has_booking == 2) { $booking = mt_rand(250, 550); } else { $booking = null; } if ($has_deposit == 1) { $deposit = mt_rand(1, 100); } elseif ($has_deposit == 2) { $deposit = mt_rand(350, 1550); } else { $deposit = null; } $cleaning = !$has_cleaning ? mt_rand(50, 350) : null; $area_total = mt_rand(45, 300); $area_garden = intval(0.4 * $area_total); $area_terrace = intval(0.2 * $area_total); $newAd = App\Ad::create(); $newRentVacation = \App\Lodging::create(['ad_id' => $newAd->id, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'surroundings_id' => mt_rand(1, $n_surroundings_options), 'category_lodging_id' => mt_rand(1, $n_lodging_categories), 'has_multiple_lodgings' => mt_rand(0, 1), 'area_total' => $area_total, 'area_garden' => $area_garden, 'area_terrace' => $area_terrace, 'distance_to_beach' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_town_center' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_ski_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_golf_course' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_airport' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_supermarket' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_river_or_lake' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_marina' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_horse_riding_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_scuba_diving_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_train_station' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_bus_station' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_hospital' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'distance_to_hiking_area' => mt_rand(0, 5) ? null : mt_rand(250, 10000), 'n_double_bedroom' => $n_d_b, 'n_two_beds_room' => $n_2_b, 'n_single_bed_room' => $n_1_b, 'n_three_beds_room' => $n_3_b, 'n_four_beds_room' => $n_4_b, 'n_sofa_bed' => $n_sb, 'n_double_sofa_bed' => $n_d_sb, 'n_extra_bed' => $n_eb, 'min_capacity' => $min_capacity, 'max_capacity' => $max_capacity, 'payment_day_id' => $payment_day, 'n_days_before' => $days_before, 'has_booking' => $has_booking, 'booking' => $booking, 'has_deposit' => $has_deposit, 'deposit' => $deposit, 'has_cleaning' => $has_cleaning, 'cleaning' => $cleaning, 'has_included_towels' => mt_rand(0, 1), 'has_included_expenses' => mt_rand(0, 1), 'accepts_cash' => mt_rand(0, 1), 'accepts_transfer' => mt_rand(0, 1), 'accepts_credit_card' => mt_rand(0, 1), 'accepts_paypal' => mt_rand(0, 1), 'accepts_check' => mt_rand(0, 1), 'accepts_western_union' => mt_rand(0, 1), 'accepts_money_gram' => mt_rand(0, 1), 'has_barbecue' => mt_rand(0, 1), 'has_terrace' => mt_rand(0, 1), 'has_private_swimming_pool' => mt_rand(0, 1), 'has_shared_swimming_pool' => mt_rand(0, 1), 'has_indoor_swimming_pool' => mt_rand(0, 1), 'has_private_garden' => mt_rand(0, 1), 'has_shared_garden' => mt_rand(0, 1), 'has_furnished_garden' => mt_rand(0, 1), 'has_parking_space' => mt_rand(0, 1), 'has_playground' => mt_rand(0, 1), 'has_mountain_sights' => mt_rand(0, 1), 'has_sea_sights' => mt_rand(0, 1), 'has_fireplace' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_jacuzzi' => mt_rand(0, 1), 'has_tv' => mt_rand(0, 1), 'has_cable_tv' => mt_rand(0, 1), 'has_internet' => mt_rand(0, 1), 'has_heating' => mt_rand(0, 1), 'has_fan' => mt_rand(0, 1), 'has_cradle' => mt_rand(0, 1), 'has_hairdryer' => mt_rand(0, 1), 'has_dishwasher' => mt_rand(0, 1), 'has_fridge' => mt_rand(0, 1), 'has_oven' => mt_rand(0, 1), 'has_microwave' => mt_rand(0, 1), 'has_coffee_maker' => mt_rand(0, 1), 'has_dryer' => mt_rand(0, 1), 'has_washer' => mt_rand(0, 1), 'has_iron' => mt_rand(0, 1), 'is_smoking_allowed' => mt_rand(0, 1), 'is_pet_allowed' => mt_rand(0, 1), 'has_elevator' => mt_rand(0, 1), 'is_car_recommended' => mt_rand(0, 1), 'is_handicapped_adapted' => mt_rand(0, 1), 'is_out_town_center' => mt_rand(0, 1), 'is_isolated' => mt_rand(0, 1), 'is_nudist_area' => mt_rand(0, 1), 'is_bar_area' => mt_rand(0, 1), 'is_gayfriendly_area' => mt_rand(0, 1), 'is_family_tourism_area' => mt_rand(0, 1), 'is_luxury_area' => mt_rand(0, 1), 'is_charming' => mt_rand(0, 1), 'has_bicycle_rental' => mt_rand(0, 1), 'has_car_rental' => mt_rand(0, 1), 'has_adventure_activities' => mt_rand(0, 1), 'has_kindergarten' => mt_rand(0, 1), 'has_sauna' => mt_rand(0, 1), 'has_tennis_court' => mt_rand(0, 1), 'has_paddle_court' => mt_rand(0, 1), 'has_gym' => mt_rand(0, 1), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_vacation'; $newAd->local_id = $newRentVacation->id; $newAd->save(); $this->command->info('Seeded Rent Vacation (id: ' . $newRentVacation->id . ')'); $n_seasons_prices = mt_rand(1, 4); for ($j = 0; $j < $n_seasons_prices; $j++) { $from_date = \Carbon\Carbon::createFromDate(null, mt_rand(1, 12), 1); $to_date = $from_date->addMonths(mt_rand(1, 6)); $newSeasonPrice = \App\SeasonPrice::create(['n_season' => $j, 'from_date' => $j == 0 ? \Carbon\Carbon::createFromFormat('d/m/Y', '1/1/1900') : $from_date, 'to_date' => $j == 0 ? \Carbon\Carbon::createFromFormat('d/m/Y', '1/1/2999') : $to_date, 'p_one_night' => mt_rand(15, 100), 'p_weekend_night' => mt_rand(30, 200), 'p_one_week' => mt_rand(80, 700), 'p_half_month' => mt_rand(150, 1400), 'p_one_month' => mt_rand(300, 2800), 'p_extra_guest_per_night' => mt_rand(7, 50), 'n_min_nights' => mt_rand(1, 60), 'rent_vacation_id' => $newRentVacation->id]); $this->command->info('Seeded Season Price (id: ' . $newSeasonPrice->id . ') for Rent Vacation (id: ' . $newRentVacation->id . ')'); } } for ($i = 0; $i < THIS_MANY_ADS; $i++) { $location = \App\Geocode::generateRandomLocation(); $price = mt_rand(250, 700); $deposit = mt_rand(0, 6) ? $deposits[array_rand($deposits)] : null; $has_block = mt_rand(0, 1); $block_name = $has_block ? $blocks[array_rand($blocks)] : null; $n_bedrooms = mt_rand(2, 5); $n_people = intval($n_bedrooms / 2 + 1); $newAd = App\Ad::create(); $newRentRoom = \App\Room::create(['ad_id' => $newAd->id, 'price' => $price, 'deposit' => $deposit, 'lat' => isset($location['lat']) ? $location['lat'] : '', 'lng' => isset($location['lng']) ? $location['lng'] : '', 'formatted_address' => isset($location['formatted_address']) ? $location['formatted_address'] : '', 'street_number' => isset($location['street_number']) ? $location['street_number'] : '', 'route' => isset($location['route']) ? $location['route'] : '', 'locality' => isset($location['locality']) ? $location['locality'] : '', 'admin_area_lvl2' => isset($location['administrative_area_level_2']) ? $location['administrative_area_level_2'] : '', 'admin_area_lvl1' => isset($location['administrative_area_level_1']) ? $location['administrative_area_level_1'] : '', 'country' => isset($location['country']) ? $location['country'] : '', 'postal_code' => isset($location['postal_code']) ? $location['postal_code'] : '', 'hide_address' => mt_rand(0, 1), 'floor_number' => $floors[array_rand($floors)], 'is_last_floor' => mt_rand(0, 1), 'door' => $doors[array_rand($doors)], 'has_block' => $has_block, 'block' => $block_name, 'residential_area' => mt_rand(0, 5) ? null : $faker->name, 'category_room_id' => mt_rand(1, $n_room_categories), 'area_room' => mt_rand(10, 50), 'n_people' => $n_people, 'n_bedrooms' => $n_bedrooms, 'n_bathrooms' => mt_rand(1, 2), 'current_tenants_gender_id' => mt_rand(1, $n_current_tenants_gender_options), 'is_smoking_allowed' => mt_rand(0, 1), 'is_pet_allowed' => mt_rand(0, 1), 'min_current_tenants_age' => mt_rand(18, 23), 'max_current_tenants_age' => mt_rand(23, 35), 'has_elevator' => mt_rand(0, 1), 'has_furniture' => mt_rand(0, 1), 'has_builtin_closets' => mt_rand(0, 1), 'has_air_conditioning' => mt_rand(0, 1), 'has_internet' => mt_rand(0, 1), 'has_house_keeper' => mt_rand(0, 1), 'tenant_gender_id' => mt_rand(1, $n_tenant_gender_options), 'tenant_occupation_id' => mt_rand(1, $n_tenant_occupation_options), 'tenant_sexual_orientation_id' => mt_rand(1, $n_tenant_sexual_orientation_options), 'tenant_min_stay_id' => mt_rand(1, $n_tenant_min_stay_options), 'description' => $faker->text(1020)]); $newAd->local_table = 'rent_room'; $newAd->local_id = $newRentRoom->id; $newAd->save(); $this->command->info('Seeded Rent Room (id: ' . $newRentRoom->id . ')'); } foreach (\App\Ad::all() as $ad) { $n_pics = mt_rand(0, 12); for ($i = 0; $i < $n_pics; ++$i) { \App\AdPic::create(['ad_id' => $ad->id, 'filename' => 'http://lorempixel.com/640/480/city/Faker']); $this->command->info('Seeded Pictures for Ad (id: ' . $ad->id . ')'); } } }
public function adProfile($id) { $Ad = Ad::findOrFail($id); //specific operation and typology codes for the profile page $txt = explode('_', $Ad->local_table, 2); switch ($txt[0]) { case 'sell': switch ($txt[1]) { case 'house': $ad = SellHouse::findOrFail($Ad->local_id); break; case 'apartment': $ad = SellApartment::findOrFail($Ad->local_id); break; case 'country_house': $ad = SellCountryHouse::findOrFail($Ad->local_id); break; case 'business': $ad = SellBusiness::findOrFail($Ad->local_id); break; case 'office': $ad = SellOffice::findOrFail($Ad->local_id); break; case 'garage': $ad = SellGarage::findOrFail($Ad->local_id); break; case 'land': $ad = SellLand::findOrFail($Ad->local_id); break; } break; case 'rent': switch ($txt[1]) { case 'house': $ad = RentHouse::findOrFail($Ad->local_id); break; case 'apartment': $ad = RentApartment::findOrFail($Ad->local_id); break; case 'country_house': $ad = RentCountryHouse::findOrFail($Ad->local_id); break; case 'business': $ad = RentBusiness::findOrFail($Ad->local_id); break; case 'office': $ad = RentOffice::findOrFail($Ad->local_id); break; case 'garage': $ad = RentGarage::findOrFail($Ad->local_id); break; case 'land': $ad = RentLand::findOrFail($Ad->local_id); break; case 'room': $ad = Room::findOrFail($Ad->local_id); break; case 'vacation': $ad = Lodging::findOrFail($Ad->local_id); break; } break; } switch ($txt[0]) { case 'sell': $operation = 0; break; case 'rent': $operation = 1; break; } switch ($txt[1]) { case 'house': $typology = 0; $ad->type = CategoryHouse::where('id', $ad->category_house_id)->pluck('name'); break; case 'apartment': $typology = 1; if ($ad->is_duplex) { $ad->type = 'Dúplex'; } elseif ($ad->is_penthouse) { $ad->type = 'Ático'; } elseif ($ad->is_studio) { $ad->type = 'Estudio'; } else { $ad->type = 'Piso'; } break; case 'country_house': $typology = 2; $ad->type = CategoryCountryHouse::where('id', $ad->category_country_house_id)->pluck('name'); break; case 'business': $typology = 3; $ad->type = CategoryBusiness::where('id', $ad->category_business_id)->pluck('name'); $ad->distribution = OptionBusinessDistribution::where('id', $ad->business_distribution_id)->pluck('name'); $ad->facade = OptionBusinessFacade::where('id', $ad->business_facade_id)->pluck('name'); $ad->location = OptionBusinessLocation::where('id', $ad->business_location_id)->pluck('name'); break; case 'office': $typology = 4; $ad->type = 'Oficina'; $ad->distribution = OptionOfficeDistribution::where('id', $ad->office_distribution_id)->pluck('name'); break; case 'garage': $typology = 5; $ad->type = 'Garaje'; $ad->garage_capacity = OptionGarageCapacity::where('id', $ad->garage_capacity_id)->pluck('name'); break; case 'land': $typology = 6; $ad->type = 'Terreno'; $ad->category_land = CategoryLand::where('id', $ad->category_land_id)->pluck('name'); $ad->nearest_town = OptionNearestTownDistance::where('id', $ad->nearest_town_distance_id)->pluck('name'); break; case 'room': $typology = 7; $ad->type = 'Habitación'; $ad->category_room = CategoryRoom::where('id', $ad->category_room_id)->pluck('name'); $ad->min_stay = OptionTenantMinStay::where('id', $ad->tenant_min_stay_id)->pluck('name'); $ad->current_gender = OptionCurrentTenantsGender::where('id', $ad->current_tenants_gender_id)->pluck('name'); $ad->gender = OptionTenantGender::where('id', $ad->tenant_gender_id)->pluck('name'); $ad->occupation = OptionTenantOccupation::where('id', $ad->tenant_occupation_id)->pluck('name'); $ad->sexual_orientation = OptionTenantSexualOrientation::where('id', $ad->tenant_sexual_orientation_id)->pluck('name'); break; case 'vacation': $typology = 8; $ad->type = CategoryLodging::where('id', $ad->category_lodging_id)->pluck('name'); $ad->surroundings = OptionSurroundings::where('id', $ad->surroundings_id)->pluck('name'); $ad->min_price_per_night = \DB::select(\DB::raw("\n SELECT MIN(t2.p_one_month) as min_price_per_night\n FROM rent_vacation AS t1\n LEFT JOIN vacation_season_price AS t2 ON t1.id = t2.rent_vacation_id\n WHERE t1.id = ?;\n "), [$ad->id]); $ad->season_prices = SeasonPrice::where('rent_vacation_id', $ad->id)->get(); $ad->payment_day = OptionPaymentDay::where('id', $ad->payment_day_id)->pluck('name'); break; } return view('ad', compact('ad', 'operation', 'typology')); }
public function doEditAd() { $input = \Input::all(); //input 'corrections' if (isset($input['door'])) { if ($input['door'] == '0') { $input['door'] = $input['door_letter']; } else { if ($input['door'] == '1') { $input['door'] = $input['door_number']; } } } if (isset($input['has_booking'])) { if ($input['has_booking'] == '1') { $input['booking'] = $input['booking-percentage']; } else { if ($input['has_booking'] == '2') { $input['booking'] = $input['booking-euros']; } } } if (isset($input['has_deposit'])) { if ($input['has_deposit'] == '1') { $input['deposit'] = $input['deposit-percentage']; } else { if ($input['has_deposit'] == '2') { $input['deposit'] = $input['deposit-euros']; } } } //Find old Ad $Ad = Ad::findOrFail($input['ad_id']); //Delete old pics if ($Ad->pics->count()) { $Ad->pics()->delete(); } //Associate new pictures with the Ad foreach ($input as $key => $value) { $exp_key = explode('_', $key); if ($exp_key[0] == 'pictures') { $pictures[] = ['filename' => $value]; } } if (isset($pictures)) { foreach ($pictures as $picture) { AdPic::create(['filename' => $picture['filename'], 'ad_id' => $input['ad_id']]); } } //Save the new info switch ($input['operation']) { case '0': //sell switch ($input['typology']) { case '0': //apartment $old = SellApartment::find($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->is_last_floor = isset($input['is_last_floor']) && $input['is_last_floor'] ? true : false; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->is_regular = isset($input['is_regular']) && $input['is_regular'] ? true : false; $old->is_penthouse = isset($input['is_penthouse']) && $input['is_penthouse'] ? true : false; $old->is_duplex = isset($input['is_duplex']) && $input['is_duplex'] ? true : false; $old->is_studio = isset($input['is_studio']) && $input['is_studio'] ? true : false; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->is_exterior = isset($input['is_exterior']) && $input['is_exterior'] ? true : false; $old->has_elevator = isset($input['has_elevator']) && $input['has_elevator'] ? true : false; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->description = $input['description']; break; case '1': //house $old = SellHouse::findOrFail($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_house_id = $input['category_house_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_land = $input['area_land']; $old->n_floors = $input['n_floors']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->has_fireplace = isset($input['has_fireplace']) && $input['has_fireplace'] ? true : false; $old->description = $input['description']; break; case '2': //country house $old = SellCountryHouse::findOrFail($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_country_house_id = $input['category_country_house_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_land = $input['area_land']; $old->n_floors = $input['n_floors']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->has_fireplace = isset($input['has_fireplace']) && $input['has_fireplace'] ? true : false; $old->description = $input['description']; break; case '3': //office $old = SellOffice::findOrFail($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_min_for_sale = $input['area_min_for_sale']; $old->n_floors = $input['n_floors']; $old->has_offices_only = isset($input['has_offices_only']) && $input['has_offices_only'] ? true : false; $old->office_distribution_id = $input['office_distribution_id']; $old->n_restrooms = $input['n_restrooms']; $old->has_bathrooms = isset($input['has_bathrooms']) && $input['has_bathrooms'] ? true : false; $old->has_bathrooms_inside = isset($input['has_bathrooms_inside']) && $input['has_bathrooms_inside'] ? true : false; $old->is_exterior = isset($input['is_exterior']) && $input['is_exterior'] ? true : false; $old->n_elevators = $input['n_elevators']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->n_parking_spaces = $input['n_parking_spaces']; $old->has_steel_door = isset($input['has_steel_door']) && $input['has_steel_door'] ? true : false; $old->has_security_system = isset($input['has_security_system']) && $input['has_security_system'] ? true : false; $old->has_access_control = isset($input['has_access_control']) && $input['has_access_control'] ? true : false; $old->has_fire_detectors = isset($input['has_fire_detectors']) && $input['has_fire_detectors'] ? true : false; $old->has_fire_extinguishers = isset($input['has_fire_extinguishers']) && $input['has_fire_extinguishers'] ? true : false; $old->has_fire_sprinklers = isset($input['has_fire_sprinklers']) && $input['has_fire_sprinklers'] ? true : false; $old->has_fireproof_doors = isset($input['has_fireproof_doors']) && $input['has_fireproof_doors'] ? true : false; $old->has_emergency_lights = isset($input['has_emergency_lights']) && $input['has_emergency_lights'] ? true : false; $old->has_doorman = isset($input['has_doorman']) && $input['has_doorman'] ? true : false; $old->has_air_conditioning_preinstallation = isset($input['has_air_conditioning_preinstallation']) && $input['has_air_conditioning_preinstallation'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_heating = isset($input['has_heating']) && $input['has_heating'] ? true : false; $old->has_hot_water = isset($input['has_hot_water']) && $input['has_hot_water'] ? true : false; $old->has_kitchen = isset($input['has_kitchen']) && $input['has_kitchen'] ? true : false; $old->has_archive = isset($input['has_archive']) && $input['has_archive'] ? true : false; $old->has_double_windows = isset($input['has_double_windows']) && $input['has_double_windows'] ? true : false; $old->has_suspended_ceiling = isset($input['has_suspended_ceiling']) && $input['has_suspended_ceiling'] ? true : false; $old->has_suspended_floor = isset($input['has_suspended_floor']) && $input['has_suspended_floor'] ? true : false; $old->is_handicapped_adapted = isset($input['is_handicapped_adapted']) && $input['is_handicapped_adapted'] ? true : false; $old->description = $input['description']; break; case '4': //business $old = SellBusiness::findOrFail($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->category_business_id = $input['category_business_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->business_distribution_id = $input['business_distribution_id']; $old->business_facade_id = $input['business_facade_id']; $old->n_shop_windows = $input['n_shop_windows']; $old->business_location_id = $input['business_location_id']; $old->n_floors = $input['n_floors']; $old->n_restrooms = $input['n_restrooms']; $old->last_activity = $input['last_activity']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->has_archive = isset($input['has_archive']) && $input['has_archive'] ? true : false; $old->has_smoke_extractor = isset($input['has_smoke_extractor']) && $input['has_smoke_extractor'] ? true : false; $old->has_fully_equipped_kitchen = isset($input['has_fully_equipped_kitchen']) && $input['has_fully_equipped_kitchen'] ? true : false; $old->has_steel_door = isset($input['has_steel_door']) && $input['has_steel_door'] ? true : false; $old->has_alarm = isset($input['has_alarm']) && $input['has_alarm'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_heating = isset($input['has_heating']) && $input['has_heating'] ? true : false; $old->has_security_camera = isset($input['has_security_camera']) && $input['has_security_camera'] ? true : false; $old->is_corner_located = isset($input['is_corner_located']) && $input['is_corner_located'] ? true : false; $old->description = $input['description']; break; case '5': //garage $old = SellGarage::findOrFail($input['local_id']); $old->price = $input['price']; $old->community_cost = $input['community_cost']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->garage_capacity_id = $input['garage_capacity_id']; $old->is_covered = isset($input['is_covered']) && $input['is_covered'] ? true : false; $old->has_automatic_door = isset($input['has_automatic_door']) && $input['has_automatic_door'] ? true : false; $old->has_lift = isset($input['has_lift']) && $input['has_lift'] ? true : false; $old->has_alarm = isset($input['has_alarm']) && $input['has_alarm'] ? true : false; $old->has_security_camera = isset($input['has_security_camera']) && $input['has_security_camera'] ? true : false; $old->has_security_guard = isset($input['has_security_guard']) && $input['has_security_guard'] ? true : false; $old->description = $input['description']; break; case '6': //land $old = SellLand::findOrFail($input['local_id']); $old->price = $input['price']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_land_id = $input['category_land_id']; $old->area_total = $input['area_total']; $old->area_building_land = $input['area_building_land']; $old->area_min_for_sale = $input['area_min_for_sale']; $old->is_classified_residential_block = isset($input['is_classified_residential_block']) && $input['is_classified_residential_block'] ? true : false; $old->is_classified_residential_house = isset($input['is_classified_residential_house']) && $input['is_classified_residential_house'] ? true : false; $old->is_classified_office = isset($input['is_classified_office']) && $input['is_classified_office'] ? true : false; $old->is_classified_commercial = isset($input['is_classified_commercial']) && $input['is_classified_commercial'] ? true : false; $old->is_classified_hotel = isset($input['is_classified_hotel']) && $input['is_classified_hotel'] ? true : false; $old->is_classified_industrial = isset($input['is_classified_industrial']) && $input['is_classified_industrial'] ? true : false; $old->is_classified_public_service = isset($input['is_classified_public_service']) && $input['is_classified_public_service'] ? true : false; $old->is_classified_others = isset($input['is_classified_others']) && $input['is_classified_others'] ? true : false; $old->max_floors_allowed = $input['max_floors_allowed']; $old->has_road_access = isset($input['has_road_access']) && $input['has_road_access'] ? true : false; $old->nearest_town_distance_id = $input['nearest_town_distance_id']; $old->has_water = isset($input['has_water']) && $input['has_water'] ? true : false; $old->has_electricity = isset($input['has_electricity']) && $input['has_electricity'] ? true : false; $old->has_sewer_system = isset($input['has_sewer_system']) && $input['has_sewer_system'] ? true : false; $old->has_natural_gas = isset($input['has_natural_gas']) && $input['has_natural_gas'] ? true : false; $old->has_street_lighting = isset($input['has_street_lighting']) && $input['has_street_lighting'] ? true : false; $old->has_sidewalks = isset($input['has_sidewalks']) && $input['has_sidewalks'] ? true : false; $old->description = $input['description']; break; } break; case '1': //rent switch ($input['typology']) { case '0': //apartment $old = RentApartment::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->is_last_floor = isset($input['is_last_floor']) && $input['is_last_floor'] ? true : false; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->is_regular = isset($input['is_regular']) && $input['is_regular'] ? true : false; $old->is_penthouse = isset($input['is_penthouse']) && $input['is_penthouse'] ? true : false; $old->is_duplex = isset($input['is_duplex']) && $input['is_duplex'] ? true : false; $old->is_studio = isset($input['is_studio']) && $input['is_studio'] ? true : false; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->is_exterior = isset($input['is_exterior']) && $input['is_exterior'] ? true : false; $old->has_equipped_kitchen = isset($input['has_equipped_kitchen']) && $input['has_equipped_kitchen'] ? true : false; $old->has_furniture = isset($input['has_furniture']) && $input['has_furniture'] ? true : false; $old->has_elevator = isset($input['has_elevator']) && $input['has_elevator'] ? true : false; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->description = $input['description']; break; case '1': //house $old = RentHouse::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_house_id = $input['category_house_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_land = $input['area_land']; $old->n_floors = $input['n_floors']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->has_equipped_kitchen = isset($input['has_equipped_kitchen']) && $input['has_equipped_kitchen'] ? true : false; $old->has_furniture = isset($input['has_furniture']) && $input['has_furniture'] ? true : false; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_fireplace = isset($input['has_fireplace']) && $input['has_fireplace'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->description = $input['description']; break; case '2': //country house $old = RentCountryHouse::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->is_bank_agency = isset($input['is_bank_agency']) && $input['is_bank_agency'] ? true : false; $old->is_state_subsidized = isset($input['is_state_subsidized']) && $input['is_state_subsidized'] ? true : false; $old->is_new_development = isset($input['is_new_development']) && $input['is_new_development'] ? true : false; $old->is_new_development_finished = isset($input['is_new_development_finished']) && $input['is_new_development_finished'] ? true : false; $old->is_rent_to_own = isset($input['is_rent_to_own']) && $input['is_rent_to_own'] ? true : false; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_country_house_id = $input['category_country_house_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_land = $input['area_land']; $old->n_floors = $input['n_floors']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->has_equipped_kitchen = isset($input['has_equipped_kitchen']) && $input['has_equipped_kitchen'] ? true : false; $old->has_furniture = isset($input['has_furniture']) && $input['has_furniture'] ? true : false; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->faces_north = isset($input['faces_north']) && $input['faces_north'] ? true : false; $old->faces_south = isset($input['faces_south']) && $input['faces_south'] ? true : false; $old->faces_east = isset($input['faces_east']) && $input['faces_east'] ? true : false; $old->faces_west = isset($input['faces_west']) && $input['faces_west'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_box_room = isset($input['has_box_room']) && $input['has_box_room'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_fireplace = isset($input['has_fireplace']) && $input['has_fireplace'] ? true : false; $old->has_swimming_pool = isset($input['has_swimming_pool']) && $input['has_swimming_pool'] ? true : false; $old->has_garden = isset($input['has_garden']) && $input['has_garden'] ? true : false; $old->description = $input['description']; break; case '3': //office $old = RentOffice::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->area_min_for_sale = $input['area_min_for_sale']; $old->n_floors = $input['n_floors']; $old->has_offices_only = isset($input['']) && $input[''] ? true : false; $old->office_distribution_id = $input['office_distribution_id']; $old->n_restrooms = $input['n_restrooms']; $old->has_bathrooms = isset($input['has_bathrooms']) && $input['has_bathrooms'] ? true : false; $old->has_bathrooms_inside = isset($input['has_bathrooms_inside']) && $input['has_bathrooms_inside'] ? true : false; $old->is_exterior = isset($input['is_exterior']) && $input['is_exterior'] ? true : false; $old->n_elevators = $input['n_elevators']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->n_parking_spaces = $input['n_parking_spaces']; $old->has_steel_door = isset($input['has_steel_door']) && $input['has_steel_door'] ? true : false; $old->has_security_system = isset($input['has_security_system']) && $input['has_security_system'] ? true : false; $old->has_access_control = isset($input['has_access_control']) && $input['has_access_control'] ? true : false; $old->has_fire_detectors = isset($input['has_fire_detectors']) && $input['has_fire_detectors'] ? true : false; $old->has_fire_extinguishers = isset($input['has_fire_extinguishers']) && $input['has_fire_extinguishers'] ? true : false; $old->has_fire_sprinklers = isset($input['has_fire_sprinklers']) && $input['has_fire_sprinklers'] ? true : false; $old->has_fireproof_doors = isset($input['has_fireproof_doors']) && $input['has_fireproof_doors'] ? true : false; $old->has_emergency_lights = isset($input['has_emergency_lights']) && $input['has_emergency_lights'] ? true : false; $old->has_doorman = isset($input['has_doorman']) && $input['has_doorman'] ? true : false; $old->has_air_conditioning_preinstallation = isset($input['has_air_conditioning_preinstallation']) && $input['has_air_conditioning_preinstallation'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_heating = isset($input['has_heating']) && $input['has_heating'] ? true : false; $old->has_hot_water = isset($input['has_hot_water']) && $input['has_hot_water'] ? true : false; $old->has_kitchen = isset($input['has_kitchen']) && $input['has_kitchen'] ? true : false; $old->has_archive = isset($input['has_archive']) && $input['has_archive'] ? true : false; $old->has_double_windows = isset($input['has_double_windows']) && $input['has_double_windows'] ? true : false; $old->has_suspended_ceiling = isset($input['has_suspended_ceiling']) && $input['has_suspended_ceiling'] ? true : false; $old->has_suspended_floor = isset($input['has_suspended_floor']) && $input['has_suspended_floor'] ? true : false; $old->is_handicapped_adapted = isset($input['is_handicapped_adapted']) && $input['is_handicapped_adapted'] ? true : false; $old->description = $input['description']; break; case '4': //business $old = RentBusiness::findOrFail($input['local_id']); $old->price = $input['price']; $old->is_transfer = isset($input['is_transfer']) && $input['is_transfer'] ? true : false; $old->deposit = $input['deposit']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->category_business_id = $input['category_business_id']; $old->needs_restoration = isset($input['needs_restoration']) && $input['needs_restoration'] ? true : false; $old->area_constructed = $input['area_constructed']; $old->area_usable = $input['area_usable']; $old->business_distribution_id = $input['business_distribution_id']; $old->business_facade_id = $input['business_facade_id']; $old->n_shop_windows = $input['n_shop_windows']; $old->business_location_id = $input['business_location_id']; $old->n_floors = $input['n_floors']; $old->n_restrooms = $input['n_restrooms']; $old->last_activity = $input['last_activity']; $old->energy_certification_id = $input['energy_certification_id']; $old->energy_performance = $input['energy_performance']; $old->has_archive = isset($input['has_archive']) && $input['has_archive'] ? true : false; $old->has_smoke_extractor = isset($input['has_smoke_extractor']) && $input['has_smoke_extractor'] ? true : false; $old->has_fully_equipped_kitchen = isset($input['has_fully_equipped_kitchen']) && $input['has_fully_equipped_kitchen'] ? true : false; $old->has_steel_door = isset($input['has_steel_door']) && $input['has_steel_door'] ? true : false; $old->has_alarm = isset($input['has_alarm']) && $input['has_alarm'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_heating = isset($input['has_heating']) && $input['has_heating'] ? true : false; $old->has_security_camera = isset($input['has_security_camera']) && $input['has_security_camera'] ? true : false; $old->is_corner_located = isset($input['is_corner_located']) && $input['is_corner_located'] ? true : false; $old->description = $input['description']; break; case '5': //garage $old = RentGarage::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->garage_capacity_id = $input['garage_capacity_id']; $old->is_covered = isset($input['is_covered']) && $input['is_covered'] ? true : false; $old->has_automatic_door = isset($input['has_automatic_door']) && $input['has_automatic_door'] ? true : false; $old->has_lift = isset($input['has_lift']) && $input['has_lift'] ? true : false; $old->has_alarm = isset($input['has_alarm']) && $input['has_alarm'] ? true : false; $old->has_security_camera = isset($input['has_security_camera']) && $input['has_security_camera'] ? true : false; $old->has_security_guard = isset($input['has_security_guard']) && $input['has_security_guard'] ? true : false; $old->description = $input['description']; break; case '6': //land $old = RentLand::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->residential_area = $input['residential_area']; $old->category_land_id = $input['category_land_id']; $old->area_total = $input['area_total']; $old->area_building_land = $input['area_building_land']; $old->area_min_for_sale = $input['area_min_for_sale']; $old->is_classified_residential_block = isset($input['is_classified_residential_block']) && $input['is_classified_residential_block'] ? true : false; $old->is_classified_residential_house = isset($input['is_classified_residential_house']) && $input['is_classified_residential_house'] ? true : false; $old->is_classified_office = isset($input['is_classified_office']) && $input['is_classified_office'] ? true : false; $old->is_classified_commercial = isset($input['is_classified_commercial']) && $input['is_classified_commercial'] ? true : false; $old->is_classified_hotel = isset($input['is_classified_hotel']) && $input['is_classified_hotel'] ? true : false; $old->is_classified_industrial = isset($input['is_classified_industrial']) && $input['is_classified_industrial'] ? true : false; $old->is_classified_public_service = isset($input['is_classified_public_service']) && $input['is_classified_public_service'] ? true : false; $old->is_classified_others = isset($input['is_classified_others']) && $input['is_classified_others'] ? true : false; $old->max_floors_allowed = $input['max_floors_allowed']; $old->has_road_access = isset($input['has_road_access']) && $input['has_road_access'] ? true : false; $old->nearest_town_distance_id = $input['nearest_town_distance_id']; $old->has_water = isset($input['has_water']) && $input['has_water'] ? true : false; $old->has_electricity = isset($input['has_electricity']) && $input['has_electricity'] ? true : false; $old->has_sewer_system = isset($input['has_sewer_system']) && $input['has_sewer_system'] ? true : false; $old->has_natural_gas = isset($input['has_natural_gas']) && $input['has_natural_gas'] ? true : false; $old->has_street_lighting = isset($input['has_street_lighting']) && $input['has_street_lighting'] ? true : false; $old->has_sidewalks = isset($input['has_sidewalks']) && $input['has_sidewalks'] ? true : false; $old->description = $input['description']; break; case '7': //vacation (lodging) $old = Lodging::findOrFail($input['local_id']); $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->is_last_floor = isset($input['is_last_floor']) && $input['is_last_floor'] ? true : false; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->surroundings_id = $input['surroundings_id']; $old->category_lodging_id = $input['category_lodging_id']; $old->has_multiple_lodgings = isset($input['has_multiple_lodgings']) && $input['has_multiple_lodgings'] ? true : false; $old->area_total = $input['area_total']; $old->area_garden = $input['area_garden']; $old->area_terrace = $input['area_terrace']; $old->is_american_kitchen = isset($input['is_american_kitchen']) && $input['is_american_kitchen'] ? true : false; $old->distance_to_beach = $input['distance_to_beach']; $old->distance_to_town_center = $input['distance_to_town_center']; $old->distance_to_ski_area = $input['distance_to_ski_area']; $old->distance_to_golf_course = $input['distance_to_golf_course']; $old->distance_to_airport = $input['distance_to_airport']; $old->distance_to_supermarket = $input['distance_to_supermarket']; $old->distance_to_river_or_lake = $input['distance_to_river_or_lake']; $old->distance_to_marina = $input['distance_to_marina']; $old->distance_to_horse_riding_area = $input['distance_to_horse_riding_area']; $old->distance_to_scuba_diving_area = $input['distance_to_scuba_diving_area']; $old->distance_to_train_station = $input['distance_to_train_station']; $old->distance_to_bus_station = $input['distance_to_bus_station']; $old->distance_to_hospital = $input['distance_to_hospital']; $old->distance_to_hiking_area = $input['distance_to_hiking_area']; $old->n_double_bedroom = $input['n_double_bedroom']; $old->n_two_beds_room = $input['n_two_beds_room']; $old->n_single_bed_room = $input['n_single_bed_room']; $old->n_three_beds_room = $input['n_three_beds_room']; $old->n_four_beds_room = $input['n_four_beds_room']; $old->n_sofa_bed = $input['n_sofa_bed']; $old->n_double_sofa_bed = $input['n_double_sofa_bed']; $old->n_extra_bed = $input['n_extra_bed']; $old->min_capacity = $input['min_capacity']; $old->max_capacity = $input['max_capacity']; $old->has_booking = $input['has_booking']; $old->booking = isset($input['has_booking']) && $input['has_booking'] ? $input['booking'] : null; $old->has_deposit = $input['has_deposit']; $old->deposit = isset($input['has_deposit']) && $input['has_deposit'] ? $input['deposit'] : null; $old->payment_day_id = $input['payment_day_id']; $old->n_days_before = isset($input['n_days_before']) ? $input['n_days_before'] : null; $old->has_cleaning = isset($input['has_cleaning']) && $input['has_cleaning'] ? true : false; $old->cleaning = isset($input['has_cleaning']) && !$input['has_cleaning'] && isset($input['cleaning']) ? $input['cleaning'] : null; $old->has_included_towels = isset($input['has_included_towels']) && $input['has_included_towels'] ? true : false; $old->has_included_expenses = isset($input['has_included_expenses']) && $input['has_included_expenses'] ? true : false; $old->accepts_cash = isset($input['accepts_cash']) && $input['accepts_cash'] ? true : false; $old->accepts_transfer = isset($input['accepts_transfer']) && $input['accepts_transfer'] ? true : false; $old->accepts_credit_card = isset($input['accepts_credit_card']) && $input['accepts_credit_card'] ? true : false; $old->accepts_paypal = isset($input['accepts_paypal']) && $input['accepts_paypal'] ? true : false; $old->accepts_check = isset($input['accepts_check']) && $input['accepts_check'] ? true : false; $old->accepts_western_union = isset($input['accepts_western_union']) && $input['accepts_western_union'] ? true : false; $old->accepts_money_gram = isset($input['accepts_money_gram']) && $input['accepts_money_gram'] ? true : false; $old->has_barbecue = isset($input['has_barbecue']) && $input['has_barbecue'] ? true : false; $old->has_terrace = isset($input['has_terrace']) && $input['has_terrace'] ? true : false; $old->has_private_swimming_pool = isset($input['has_private_swimming_pool']) && $input['has_private_swimming_pool'] ? true : false; $old->has_shared_swimming_pool = isset($input['has_shared_swimming_pool']) && $input['has_shared_swimming_pool'] ? true : false; $old->has_indoor_swimming_pool = isset($input['has_indoor_swimming_pool']) && $input['has_indoor_swimming_pool'] ? true : false; $old->has_private_garden = isset($input['has_private_garden']) && $input['has_private_garden'] ? true : false; $old->has_shared_garden = isset($input['has_shared_garden']) && $input['has_shared_garden'] ? true : false; $old->has_furnished_garden = isset($input['has_furnished_garden']) && $input['has_furnished_garden'] ? true : false; $old->has_parking_space = isset($input['has_parking_space']) && $input['has_parking_space'] ? true : false; $old->has_playground = isset($input['has_playground']) && $input['has_playground'] ? true : false; $old->has_mountain_sights = isset($input['has_mountain_sights']) && $input['has_mountain_sights'] ? true : false; $old->has_sea_sights = isset($input['has_sea_sights']) && $input['has_sea_sights'] ? true : false; $old->has_fireplace = isset($input['has_fireplace']) && $input['has_fireplace'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_jacuzzi = isset($input['has_jacuzzi']) && $input['has_jacuzzi'] ? true : false; $old->has_tv = isset($input['has_tv']) && $input['has_tv'] ? true : false; $old->has_cable_tv = isset($input['has_cable_tv']) && $input['has_cable_tv'] ? true : false; $old->has_internet = isset($input['has_internet']) && $input['has_internet'] ? true : false; $old->has_heating = isset($input['has_heating']) && $input['has_heating'] ? true : false; $old->has_fan = isset($input['has_fan']) && $input['has_fan'] ? true : false; $old->has_cradle = isset($input['has_cradle']) && $input['has_cradle'] ? true : false; $old->has_hairdryer = isset($input['has_hairdryer']) && $input['has_hairdryer'] ? true : false; $old->has_dishwasher = isset($input['has_dishwasher']) && $input['has_dishwasher'] ? true : false; $old->has_fridge = isset($input['has_fridge']) && $input['has_fridge'] ? true : false; $old->has_oven = isset($input['has_oven']) && $input['has_oven'] ? true : false; $old->has_microwave = isset($input['has_microwave']) && $input['has_microwave'] ? true : false; $old->has_coffee_maker = isset($input['has_coffee_maker']) && $input['has_coffee_maker'] ? true : false; $old->has_dryer = isset($input['has_dryer']) && $input['has_dryer'] ? true : false; $old->has_washer = isset($input['has_washer']) && $input['has_washer'] ? true : false; $old->has_iron = isset($input['has_iron']) && $input['has_iron'] ? true : false; $old->is_smoking_allowed = isset($input['is_smoking_allowed']) && $input['is_smoking_allowed'] ? true : false; $old->is_pet_allowed = isset($input['is_pet_allowed']) && $input['is_pet_allowed'] ? true : false; $old->has_elevator = isset($input['has_elevator']) && $input['has_elevator'] ? true : false; $old->is_car_recommended = isset($input['is_car_recommended']) && $input['is_car_recommended'] ? true : false; $old->is_handicapped_adapted = isset($input['is_handicapped_adapter']) && $input['is_handicapped_adapter'] ? true : false; $old->is_out_town_center = isset($input['is_out_town_center']) && $input['is_out_town_center'] ? true : false; $old->is_isolated = isset($input['is_isolated']) && $input['is_isolated'] ? true : false; $old->is_nudist_area = isset($input['is_nudist_area']) && $input['is_nudist_area'] ? true : false; $old->is_bar_area = isset($input['is_bar_area']) && $input['is_bar_area'] ? true : false; $old->is_gayfriendly_area = isset($input['is_gayfriendly_area']) && $input['is_gayfriendly_area'] ? true : false; $old->is_family_tourism_area = isset($input['is_family_tourism_area']) && $input['is_family_tourism_area'] ? true : false; $old->is_luxury_area = isset($input['is_luxury_area']) && $input['is_luxury_area'] ? true : false; $old->is_charming = isset($input['is_charming']) && $input['is_charming'] ? true : false; $old->has_bicycle_rental = isset($input['has_bicycle_rental']) && $input['has_bicycle_rental'] ? true : false; $old->has_car_rental = isset($input['has_car_rental']) && $input['has_car_rental'] ? true : false; $old->has_adventure_activities = isset($input['has_adventure_activities']) && $input['has_adventure_activities'] ? true : false; $old->has_kindergarten = isset($input['has_kindergarten']) && $input['has_kindergarten'] ? true : false; $old->has_sauna = isset($input['has_sauna']) && $input['has_sauna'] ? true : false; $old->has_tennis_court = isset($input['has_tennis_court']) && $input['has_tennis_court'] ? true : false; $old->has_paddle_court = isset($input['has_paddle_court']) && $input['has_paddle_court'] ? true : false; $old->has_gym = isset($input['has_gym']) && $input['has_gym'] ? true : false; $old->description = $input['description']; //delete old prices $old->prices()->delete(); //associate new prices with old lodging foreach ($input as $key => $value) { $exp_key = explode('-', $key); if ($exp_key[0] == 'n_season') { SeasonPrice::create(['n_season' => $value, 'from_date' => Carbon::createFromFormat('d/m/Y', $input['from_date-' . $value]), 'to_date' => Carbon::createFromFormat('d/m/Y', $input['to_date-' . $value]), 'p_one_night' => $input['p_one_night-' . $value], 'p_weekend_night' => $input['p_weekend_night-' . $value], 'p_one_week' => $input['p_one_week-' . $value], 'p_half_month' => $input['p_half_month-' . $value], 'p_one_month' => $input['p_one_month-' . $value], 'p_extra_guest_per_night' => $input['p_extra_guest_per_night-' . $value], 'n_min_nights' => $input['n_min_nights-' . $value], 'rent_vacation_id' => $old->id]); } } break; case '8': //room $old = Room::findOrFail($input['local_id']); $old->price = $input['price']; $old->deposit = $input['deposit']; $old->lat = $input['lat']; $old->lng = $input['lng']; $old->formatted_address = $input['formatted_address']; $old->street_number = $input['street_number']; $old->route = $input['route']; $old->locality = $input['locality']; $old->admin_area_lvl2 = $input['admin_area_lvl2']; $old->admin_area_lvl1 = $input['admin_area_lvl1']; $old->country = $input['country']; $old->postal_code = $input['postal_code']; $old->hide_address = isset($input['hide_address']) && $input['hide_address'] ? true : false; $old->floor_number = $input['floor_number']; $old->is_last_floor = isset($input['is_last_floor']) && $input['is_last_floor'] ? true : false; $old->door = $input['door']; $old->has_block = isset($input['has_block']) && $input['has_block'] ? true : false; $old->block = isset($input['has_block']) && $input['has_block'] && isset($input['block']) ? $input['block'] : null; $old->residential_area = $input['residential_area']; $old->category_room_id = $input['category_room_id']; $old->area_room = $input['area_room']; $old->n_people = $input['n_people']; $old->n_bedrooms = $input['n_bedrooms']; $old->n_bathrooms = $input['n_bathrooms']; $old->current_tenants_gender_id = $input['current_tenants_gender_id']; $old->is_smoking_allowed = isset($input['is_smoking_allowed']) && $input['is_smoking_allowed'] ? true : false; $old->is_pet_allowed = isset($input['is_pet_allowed']) && $input['is_pet_allowed'] ? true : false; $old->min_current_tenants_age = $input['min_current_tenants_age']; $old->max_current_tenants_age = $input['max_current_tenants_age']; $old->has_elevator = isset($input['has_elevator']) && $input['has_elevator'] ? true : false; $old->has_furniture = isset($input['has_furniture']) && $input['has_furniture'] ? true : false; $old->has_builtin_closets = isset($input['has_builtin_closets']) && $input['has_builtin_closets'] ? true : false; $old->has_air_conditioning = isset($input['has_air_conditioning']) && $input['has_air_conditioning'] ? true : false; $old->has_internet = isset($input['has_internet']) && $input['has_internet'] ? true : false; $old->has_house_keeper = isset($input['has_house_keeper']) && $input['has_house_keeper'] ? true : false; $old->tenant_gender_id = $input['tenant_gender_id']; $old->tenant_occupation_id = $input['tenant_occupation_id']; $old->tenant_sexual_orientation_id = $input['tenant_sexual_orientation_id']; $old->tenant_min_stay_id = $input['tenant_min_stay_id']; $old->description = $input['description']; break; } break; } //return success to admin dashboard if (isset($old) && $old->save()) { $Ad->touch(); return redirect('dashboard')->with('success', ['Stitle' => 'Editar anuncio', 'Smsg' => 'Los datos del anuncio han sido actualizados satisfactoriamente.']); } return redirect('dashboard')->with('error', ['Etitle' => 'Editar anuncio', 'Emsg' => 'Se produjo un error al tratar de actualizar los datos del anuncio. Si el problema persiste póngase en contacto con el servicio técnico de la aplicación.']); }
public function postAdEdit(Request $request) { $rules = ['ad_title' => 'required|max:255', 'category_id' => 'required|integer|not_in:0', 'ad_description' => 'required|min:50', 'type_id' => 'required|integer|not_in:0', 'ad_image.*' => 'mimes:jpeg,bmp,png|max:300', 'location_id' => 'required|integer|not_in:0', 'ad_puslisher_name' => 'required|string|max:255', 'ad_email' => 'required|email|max:255', 'policy_agree' => 'required']; $messages = ['require_one_of_array' => 'You need to upload at least one ad pic.']; $validator = Validator::make($request->all(), $rules, $messages); /** * type 1 common ads validation */ $validator->sometimes(['ad_price_type_1'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 1 && $input->price_radio == 1) { return true; } return false; }); $validator->sometimes(['condition_id_type_1'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 1 ? 1 : 0; }); /** * type 2 estate ads validation */ $validator->sometimes(['ad_price_type_2'], 'required|numeric|not_in:0', function ($input) { if ($input->category_type == 2) { return true; } return false; }); $validator->sometimes(['estate_type_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); $validator->sometimes(['estate_sq_m'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 2 ? 1 : 0; }); /** * type 3 cars ads validation */ $validator->sometimes(['car_brand_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_model_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_engine_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_transmission_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_modification_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_year'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_kilometeres'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['car_condition_id'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['condition_id_type_3'], 'required|integer|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); $validator->sometimes(['ad_price_type_3'], 'required|numeric|not_in:0', function ($input) { return $input->category_type == 3 ? 1 : 0; }); if ($validator->fails()) { $this->throwValidationException($request, $validator); } $ad_data = $request->all(); //fill aditional fields $ad_data['user_id'] = $request->user()->user_id; $ad_data['ad_publish_date'] = date('Y-m-d H:i:s'); $ad_data['ad_valid_until'] = date('Y-m-d', mktime(null, null, null, date('m') + 1, date('d'), date('Y'))); $ad_data['ad_ip'] = Util::getRemoteAddress(); $ad_data['ad_description'] = Util::nl2br(strip_tags($ad_data['ad_description'])); switch ($ad_data['category_type']) { case 1: if ($ad_data['price_radio'] == 1) { $ad_data['ad_price'] = $ad_data['ad_price_type_1']; $ad_data['ad_free'] = 0; } else { $ad_data['ad_price'] = 0; $ad_data['ad_free'] = 1; } $ad_data['condition_id'] = $ad_data['condition_id_type_1']; break; case 2: $ad_data['ad_price'] = $ad_data['ad_price_type_2']; $ad_data['condition_id'] = $ad_data['condition_id_type_2']; break; case 3: $ad_data['ad_price'] = $ad_data['ad_price_type_3']; $ad_data['condition_id'] = $ad_data['condition_id_type_3']; break; } $ad_data['ad_description_hash'] = md5($ad_data['ad_description']); //save ad $ad = Ad::find($ad_data['ad_id']); $ad->update($ad_data); //upload and fix ad images $ad_image = Input::file('ad_image'); if (!empty(array_filter($ad_image))) { //delete current image if (!empty($ad->ad_pic)) { @unlink(public_path('uf/adata/') . '740_' . $ad->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $ad->ad_pic); } $more_pics = AdPic::where('ad_id', $ad->ad_id)->get(); if (!$more_pics->isEmpty()) { foreach ($more_pics as $k => $v) { @unlink(public_path('uf/adata/') . '740_' . $v->ad_pic); @unlink(public_path('uf/adata/') . '1000_' . $v->ad_pic); $v->delete(); } } //save new images $destination_path = public_path('uf/adata/'); $first_image_uploaded = 0; foreach ($ad_image as $k) { if (!empty($k) && $k->isValid()) { $file_name = $ad->ad_id . '_' . md5(time() + rand(0, 9999)) . '.' . $k->getClientOriginalExtension(); $k->move($destination_path, $file_name); $img = Image::make($destination_path . $file_name); $width = $img->width(); $height = $img->height(); if ($width == $height || $width > $height) { $img->heighten(1000, function ($constraint) { $constraint->upsize(); })->save($destination_path . '1000_' . $file_name); } else { $img->widen(1000, function ($constraint) { $constraint->upsize(); })->save($destination_path . '1000_' . $file_name); } if (!$first_image_uploaded) { $img->resizeCanvas(740, 740, 'top')->save($destination_path . '740_' . $file_name); $ad->ad_pic = $file_name; $ad->save(); $first_image_uploaded = 1; } else { $adPic = new AdPic(); $adPic->ad_id = $ad->ad_id; $adPic->ad_pic = $file_name; $adPic->save(); } @unlink($destination_path . $file_name); } } } $ad->ad_category_info = $this->category->getParentsByIdFlat($ad->category_id); $ad->ad_location_info = $this->location->getParentsByIdFlat($ad->location_id); $ad->pics = AdPic::where('ad_id', $ad->ad_id)->get(); $ad->same_ads = Ad::where([['ad_description_hash', $ad->ad_description_hash], ['ad_id', '<>', $ad->ad_id]])->get(); //send info mail Mail::send('emails.ad_edit', ['user' => $request->user(), 'ad' => $ad], function ($m) use($request) { $m->from('*****@*****.**', 'dclassifieds ad edit'); $m->to($request->user()->email)->subject('Your ad is edited!'); }); //send control mail Mail::send('emails.control_ad_activation', ['user' => $request->user(), 'ad' => $ad], function ($m) use($request) { $m->from('*****@*****.**', '[CONTROL] dclassifieds'); $m->to('*****@*****.**')->to('*****@*****.**')->subject('[CONTROL] dclasssifieds ad edit'); }); Cache::flush(); //set flash message and return session()->flash('message', 'Your ad is saved.'); return redirect()->back(); }
/** * Display a listing of the rejected ads. * * @return Response */ public function getRejectedList() { $ads = Ad::whereRaw('uid = ? and status = ?', [Auth::user()->id, 2])->orderBy('created_at', 'desc')->paginate(10); return view('user.ad.rejectedlist')->withAds($ads); }