public function upload(Request $request) { $listing = new Listing(); $listing->fill($request->all()); if ($request->hasFile('file')) { $file = $request->file('file'); $filename = date('U') . $file->getClientOriginalName(); $file->move(public_path('uploads/'), $filename); $listing->image = $filename; } $listing->user_id = Auth::user()->id; // $user = Auth::user // $listing->fill $listing->save(); return redirect('/'); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { /* $users = User::all(); $listings = Listing::all();*/ $users = User::orderBy('created_at', 'desc')->limit(10)->get(); $listings = Listing::orderBy('created_at', 'desc')->limit(10)->get(); return view('admin.page.index', compact('users', 'listings')); }
public function postListing(Request $request) { $data = $request->all(); // Create listing $listing = \App\Listing::create(['address1' => $data['address1'], 'address2' => $data['address2'], 'city' => $data['city'], 'state' => $data['state'], 'zip' => $data['zip'], 'property_type' => $data['property_type'], 'condition' => $data['condition'], 'beds' => $data['beds'], 'baths' => $data['baths'], 'additional_rooms' => $data['additional_rooms'], 'approx_size' => $data['approx_size'], 'approx_age_of_kitchen' => $data['approx_age_of_kitchen'], 'approx_age_of_baths' => $data['approx_age_of_baths'], 'message' => $data['message'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'phone' => $data['phone']]); $userData = $this->mapData($data); $checkForUser = \App\User::where('email', '=', $userData['email'])->first(); if (is_null($checkForUser)) { // Create User $user = \App\User::create(['name' => $userData['name'], 'email' => $userData['email'], 'password' => bcrypt($userData['password']), 'phone' => $userData['phone']]); } $email = 'emails.listingPost'; $data['name'] = $userData['name']; $this->mailIt($email, $data); dd($request->getSession()); return redirect()->back()->with('success_message', 'Your listing has been sent for review...'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $listing = Listing::findOrFail($id); /* deletes the uploaded files unlink($listing->photos); unlink($listing->file); */ $listing->delete(); return redirect('listing'); }
public function addListing(Request $request) { //needs login to add session id if (!Auth::check()) { //This should not be possible //But in the case the user SOMEHOW is not logged in, redirect return redirect('signIn'); } $v = Validator::make($request->all(), ['title_name' => 'bail|required', 'location_name' => 'bail|required|numeric', 'floorNum_name' => 'bail|alpha_num', 'unitNum_name' => 'bail|alpha_num', 'dateFrom_name' => 'bail|required', 'dateTo_name' => 'bail', 'rent_name' => 'bail|required|numeric|min:0', 'rentalLength_name' => 'bail|numeric|min:0', 'priceDescription_name' => '', 'sqft_name' => 'min:0', 'bedrooms_name' => 'bail|numeric|min:0', 'bathrooms_name' => 'bail|numeric|min:0', 'sqftSize_name' => 'bail|numeric|min:0', 'image.*' => 'required|image', 'mls' => 'alpha_num']); //Check if validation passes. If not, redirect. if ($v->fails()) { return redirect('addListing')->withErrors($v)->withInput(); } $listing = new Listing(); $listing->location_id = Input::get('location_name'); $listing->save(); $listingInfo = new Listing_Info(); $listingInfo->listing_id = $listing->listing_id; $listingInfo->date_created = Carbon::now(); $listingInfo->is_active = true; $listingInfo->listing_title = ucwords(Input::get('title_name')); $listingInfo->listing_description = Input::get('description_name', 'No Description'); $listingInfo->price_monthly = Input::get('rent_name'); $listingInfo->price_description = Input::get('priceDescription_name', 'No Description'); $listingInfo->unit = Input::get('unitNum_name'); $listingInfo->room_level = Input::get('floorNum_name'); $listingInfo->num_bedrooms_total = Input::get('bedrooms_name'); $listingInfo->num_bathrooms_total = Input::get('bathrooms_name'); $listingInfo->num_roommates_max = Input::get('roommatesNum_name'); $listingInfo->room_size_sqft = Input::get('sqft_name', 0); //Booleans $listingInfo->has_kitchen = Input::has('kitchen_name') ? true : false; $listingInfo->has_laundry = Input::has('laundry_name') ? true : false; $listingInfo->has_yard = Input::has('yard_name') ? true : false; $listingInfo->has_furnishings = Input::has('furnishing_name') ? true : false; $listingInfo->owner_pays_internet = Input::has('internet_name') ? true : false; $listingInfo->owner_pays_water = Input::has('water_name') ? true : false; $listingInfo->owner_pays_electricity = Input::has('electricity_name') ? true : false; $listingInfo->owner_has_pets = Input::has('allergy_name') ? true : false; $listingInfo->allowed_dogs = Input::has('dogs_name') ? true : false; $listingInfo->allowed_cats = Input::has('cats_name') ? true : false; $listingInfo->allowed_other_pets = Input::has('otherPets_name') ? true : false; $listingInfo->smoke_free = Input::has('smoke_name') ? true : false; $listingInfo->details_pets = Input::get('petDescription_name'); $listingInfo->mls_number = Input::get('mls', 'N/A'); $listingInfo->rental_length_months_min = Input::get('rentalLength_name'); $listingInfo->rental_available_from = Input::get('dateFrom_name'); $listingInfo->rental_available_to = Input::get('dateTo_name', NULL); $listingInfo->save(); $imageNum = 0; foreach ($request->file('image') as $file) { $imageNum = $imageNum + 1; $file_prefix = 'images/listing_photos/'; $img = Image::make($file); $img_t = Image::make($file); $img_t->resize(600, null, function ($constraint) { $constraint->aspectRatio(); }); $filename = $file_prefix . time() . '_imgNum' . $imageNum . '_' . $listing->listing_id; $img->save($filename); $img_t->save($filename . '_thumb', 100); $lis_img = new Listing_Image(); $lis_img->listing_id = $listing->listing_id; $lis_img->image_filename = $filename; $lis_img->image_filename_thumbnail = $filename . '_thumb'; $lis_img->save(); } /* Scan new listing for saved searches match, and send SMS message */ $dbg = false; //set to true for testing $query = <<<SQL \t\t\tSELECT \t* \t\t\tFROM \thomestead.saved_searches AS SEARCH \t\t\tINNER \tJOIN homestead.users AS USER ON SEARCH.user_id = USER.user_id SQL; $searches = DB::select($query); foreach ($searches as $s) { $match = true; if ($dbg) { print "User {$s->first_name} has a search<br>"; } $str = $s->phone; $ph = ""; for ($i = 0; $i < strlen($str); $i++) { if (is_numeric($str[$i])) { $ph = $ph . $str[$i]; } } if ($ph[0] == 1) { $ph = substr($ph, 0, 11); } else { $ph = substr($ph, 0, 10); } if ($dbg) { printf("The phone is : " . $ph . "<br>"); } /* Check price range if max pricing is not in saved search */ if ($s->price_monthly_max < 2000) { if ($listingInfo->price_monthly >= $s->price_monthly_min && $listingInfo->price_monthly <= $s->price_monthly_max) { if ($dbg) { print "Price matches search criteria<br>"; } } else { $match = false; } } if ($listingInfo->num_bedrooms_total < $s->num_bedrooms_total) { $match = false; } if ($dbg) { if (!$match) { print "No match 1<br>"; } } if ($listingInfo->num_bathrooms_total < $s->num_bathrooms_total) { $match = false; } if ($dbg) { if (!$match) { print "No match 2<br>"; } } if ($listingInfo->num_roommates_max > $s->num_roommates_max) { $match = false; } if ($dbg) { if (!$match) { print "No match 3<br>"; } } if (($s->has_kitchen == 1 ? true : false) && !$listingInfo->has_kitchen) { $match = false; } if ($dbg) { if (!$match) { print "No match 4 {$listingInfo->has_kitchen} {$listingInfo->has_kitchen} " . (Input::has('kitchen_name') ? "A" : "B") . "<br>"; } } if (($s->has_laundry == 1 ? true : false) && !$listingInfo->has_laundry) { $match = false; } if ($dbg) { if (!$match) { print "No match 5<br>"; } } if (($s->has_yard == 1 ? true : false) && !$listingInfo->has_yard) { $match = false; } if ($dbg) { if (!$match) { print "No match 6<br>"; } } if (($s->has_furnishings == 1 ? true : false) && !$listingInfo->has_furnishings) { $match = false; } if ($dbg) { if (!$match) { print "No match 7<br>"; } } if (($s->owner_pays_internet == 1 ? true : false) && !$listingInfo->owner_pays_internet) { $match = false; } if ($dbg) { if (!$match) { print "No match 8<br>"; } } if (($s->owner_pays_water == 1 ? true : false) && !$listingInfo->owner_pays_water) { $match = false; } if ($dbg) { if (!$match) { print "No match 9<br>"; } } if (!($s->owner_has_pets == 1 ? true : false) && $listingInfo->owner_has_pets) { $match = false; } if ($dbg) { if (!$match) { print "No match 10<br>"; } } if (($s->allowed_dogs == 1 ? true : false) && !$listingInfo->allowed_dogs) { $match = false; } if ($dbg) { if (!$match) { print "No match 11<br>"; } } if (($s->allowed_cats == 1 ? true : false) && !$listingInfo->allowed_cats) { $match = false; } if ($dbg) { if (!$match) { print "No match 12<br>"; } } if (($s->allowed_other_pets == 1 ? true : false) && !$listingInfo->allowed_other_pets) { $match = false; } if ($dbg) { if (!$match) { print "No match 13<br>"; } } if ($match && strlen($ph) == 10) { if ($dbg) { print "This listing matches your search criteria<br>"; } $msg = <<<MSG Hello {$s->first_name}! Homestead has found a {$listingInfo->num_bedrooms_total} bedroom,{$listingInfo->num_bathrooms_total} bathroom property that matches the criteria in your saved search #{$s->saved_search_id}. Please visit our website to check out the listing for more details! Regards, The Homestead Team MSG; $em = $s->email; Mail::raw($msg, function ($message) use($ph, $msg) { $message->from('*****@*****.**', 'Homestead'); $message->to('*****@*****.**'); $message->subject($ph); }); Mail::raw($msg, function ($message) use($ph, $msg, $em) { $message->from('*****@*****.**', 'Homestead'); $message->to($em); $message->subject('Homestead listing search results'); //print "SMS sent to $ph<br>"; }); } else { if ($dbg) { print "This listing does not match your search criteria<br>"; } } } if ($dbg) { return var_dump($searches) . var_dump($listingInfo); } return redirect('houseTemplate/' . $listing->listing_id); }
public function getPropertyFromListing($ListingId) { $list = Listing::where('listing_id', '=', $ListingId)->first(); $location = $list->location; $listings = $location->listing; return view('listingByProperty', compact('listings'), compact('location')); }
public function removeListing($id) { if (Auth::guest()) { return redirect()->route('home'); } $listing = Listing::where('id', $id)->where('user_id', Auth::user()->id)->first(); if ($listing) { $listing->delete(); flash()->success("Successfully removed your listing"); return redirect()->back(); } else { flash()->error("You cannot remove that listing"); return redirect()->back(); } }