`getting the issue with the following. Unable to understand the code.
The error about trying to get property image_url
of non-object
at HandleExceptions->handleError(8, 'Trying to get property \'image_url\' of non-object', '/var/www/html/S25I05V1995A/app/Http/Controllers/HomeController.php', 234, array('request' => object(Request), 'latest_properties' => object(Collection), 'property' => object(stdClass), 'favourite' => 0, 'pd' => null)) in HomeController.php line 234
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use DB; use Mail; use
Illuminate\Support\Facades\URL;
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request; use DB; use Mail; use
Illuminate\Support\Facades\URL;
class HomeController extends BaseController {
public function update_password(Request $request) {
$this->validate($request, [
'password' => 'required|min:4',
'confirm_password' => 'required|same:password'
]);
$password = $this->encrypt_password($request->password);
DB::table('users')->where('email', $request->email)->update(['password' => $password]);
$url = BASE_URL . 'login';
return redirect($url);
}
public function new_password($token, Request $request) {
$cur_date = date('Y-m-d');
$check = DB::table('users')->where('client_id', CLIENT_ID)->where('reset_password_token',
$token)->where('reset_date', $cur_date)->first();
if (!$check) {
return view('set-new-password')->with('error', 1)->with('email', $check->email);
}
else {
return view('set-new-password')->with('error', 0)->with('email', $check->email);
}
}
public function reset_email(Request $request) {
$this->validate($request, [
'email' => 'required|exists:users,email'
]);
$token = $this->generate_hash($request->email);
$date = date('Y-m-d');
DB::table('users')->where('email', $request->email)->update(['reset_password_token' => $token,
'reset_date' => $date]);
$email = $request->email;
$data = array('token' => $token);
Mail::send('mail.password-reset', $data, function ($message)use($email) {
$message->from('gotocva@gmail.com', 'Mail from Keepers');
$message->to($email);
$message->subject('Password reset mail from keepers ');
});
return back()->with('success', 'Reset link sent to your email');
}
public function reset_password() {
return view('reset_password');
}
public function short_term() {
// echo 'client'.CLIENT_ID.',';
// echo 'ACTIVE'.ACTIVE.',';
// echo 'ZERO'.ZERO.',';exit;
$properties = DB::table('property_list')
->join('property_short_term_pricing', 'property_short_term_pricing.property_id', '=', 'property_list.id')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->get();
//echo count($properties); exit;
foreach ($properties as $property) {
$image = DB::table('property_images')->where('client_id',
CLIENT_ID)->where('property_id', $property->property_id)->first();
$property->images = DB::table('property_short_term_pricing')->where('client_id',
CLIENT_ID)->where('property_id', $property->property_id)->get();
$property->image_url = $image->image_url;
$lat = (float) $property->lat;
$lng = (float) $property->lng;
// $price_data = DB::table('property_short_term_pricing')
// ->where('client_id', CLIENT_ID)
// ->where('property_id', $property->id)->first();
$t = array('id' => $property->id, 'lat' => $lat, 'lng' => $lng, 'price' => $property->price_per_night);
$lat_lng[] = $t;
$nearby_properties[] = $property;
}
$lat_lng_url = urlencode(serialize($lat_lng));
$ars = array();
return view('short_term')->with('properties', $nearby_properties)
->with('location_url', $lat_lng_url)->with('request_data', "");
}
public function short_term_filtering(Request $request)
{
$where = array();
if($request->guests != "") { $where[]='property_list.total_guests >= "'.$request->guests.'" '; }
if($request->roomtype != "") { $where[]='property_list.room_type = "'.$request->roomtype.'" '; }
if($request->bookingmode != "") { $where[]='property_list.is_instant = "'.$request->bookingmode.'" ';
}
if($request->minprice != "" && $request->maxprice != "") { $where[]='property_list.price_per_night BETWEEN
"'.$request->minprice.'" and "'.$request->maxprice.'" '; }
if($request->minprice != "" && $request->maxprice == "") { $where[]='property_list.price_per_night <=
"'.$request->minprice.'" '; }
if($request->minprice == "" && $request->maxprice != "") {
$where[]='property_list.price_per_night <=
"'.$request->maxprice.'" ';
}
$dataWhere = implode(" and ",$where);
if($dataWhere != ""){
$properties = DB::table('property_list')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->where('property_list.property_type', '=', ZERO)
->whereRaw($dataWhere)
->get();
}
else
{
$properties = DB::table('property_list')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->where('property_list.property_type', '=', ZERO)
->get();
}
$source_location = urlencode($request->formatted_address);
$nearby_properties = array();
$lat_lng = array();
foreach ($properties as $property) {
$dest_location = $property->location;
$destination_location = urlencode($property->location);
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="
. $source_location . "&destinations=" . $destination_location .
"&key=" . GOOGLE_MAPS_API_KEY . "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response = json_decode($response);
//echo ; exit;
try {
if ($response->rows[0]->elements[0]->status != 'ZERO_RESULTS') {
$distance = (float) $response->rows[0]->elements[0]->distance->text;
if ($distance <= RADIUS) {
$property->location = $dest_location;
$property->property_id = $property->id;
$property->pricing = DB::table('property_images')->where('client_id',
CLIENT_ID)->where('property_id', $property->id)->first();
$property->images = DB::table('property_short_term_pricing')->where('client_id',
CLIENT_ID)->where('property_id', $property->id)->get();
$temp_status = ACTIVE;
if ($request->guests) {
if ($request->guests > $property->total_guests) {
$temp_status = BLOCK;
}
}
if ($request->from_date) {
$from_date = date('Y-m-d', strtotime($request->from_date));
$sql = "SELECT count(*) as count FROM `property_booking` WHERE '" . $from_date . "' between `start_date`
and `end_date` AND `property_id` = " . $property->id . "";
$query = DB::select($sql);
if ($query[0]->count > 0) {
$temp_status = BLOCK;
}
}
if ($request->to_date) {
$from_date = date('Y-m-d', strtotime($request->to_date));
$sql = "SELECT count(*) as count FROM `property_booking` WHERE '" . $from_date . "' between `start_date`
and `end_date` AND `property_id` = " . $property->id . "";
$query = DB::select($sql);
if ($query[0]->count > 0) {
$temp_status = BLOCK;
}
}
if ($temp_status == ACTIVE) {
$lat = (float) $property->lat;
$lng = (float) $property->lng;
$price_data = DB::table('property_short_term_pricing')
->where('client_id', CLIENT_ID)
->where('property_id', $property->id)->first();
$t = array('id' => $property->id, 'lat' => $lat, 'lng' => $lng, 'price' => $price_data->price_per_night);
$lat_lng[] = $t;
$nearby_properties[] = $property;
}
}
}
} catch (\Exception $e) {
}
}
$lat_lng_url = urlencode(serialize($lat_lng));
return view('short_term')->with('properties', $nearby_properties)->with('location_url',
$lat_lng_url)->with('request_data', $request);
}
public
function index(Request $request) {
//
$latest_properties = DB::table('property_list')
->leftjoin('users', 'users.id', '=', 'property_list.user_id')
->leftjoin('property_short_term_pricing', 'property_short_term_pricing.property_id', '=', 'property_list.id')
->leftjoin('property_room', 'property_room.property_id', '=', 'property_list.id')
->where('property_list.client_id', '=', CLIENT_ID)
// ->where('property_list.on_popular', '=', ACTIVE)
->where('property_list.is_complete', '=', ACTIVE)
// ->where('property_list.property_type', '=', ZERO)
->get();
//echo count($latest_properties); exit;
foreach ($latest_properties as $property) {
$favourite = DB::table('user_favourites')
->where('user_favourites.client_id', '=', CLIENT_ID)
->where('user_favourites.user_id', '=', $request->session()->get('user_id'))
->where('user_favourites.property_id', '=', $property->property_id)->count();
if ($favourite != ZERO) {
$property->is_favourite = ONE;
}
else {
$property->is_favourite = ZERO;
}
$pd = DB::table('property_images')
->where('property_images.client_id', '=', CLIENT_ID)
->where('property_images.property_id', '=', $property->property_id)
->orderBy('property_images.sort', 'asc')
->first();
//echo json_encode($pd);
$property->image_url = $pd->image_url;
}
//exit;
//echo json_encode($properties); exit;
$categories = DB::select("SELECT A.image_url,A.location,A.title FROM `home_listings` A INNER JOIN ON
`home_category` B WHERE A.category_id = B.id");
return view('home', ['latest_properties' => $latest_properties, 'categories' => $categories]);
}
public function search_property(Request $request) {
//
$where = array();
if($request->guests != "") { $where[]='property_list.total_guests >= "'.$request->guests.'" '; }
if($request->roomtype != "") { $where[]='property_list.room_type = "'.$request->roomtype.'" '; }
if($request->bookingmode != "") { $where[]='property_list.is_instant = "'.$request->bookingmode.'" ';
}
if($request->minprice != "" && $request->maxprice != "") { $where[]='property_list.price_per_night BETWEEN
"'.$request->minprice.'" and "'.$request->maxprice.'" '; }
if($request->minprice != "" && $request->maxprice == "") { $where[]='property_list.price_per_night <=
"'.$request->minprice.'" '; }
if($request->minprice == "" && $request->maxprice != "") { $where[]='property_list.price_per_night <=
"'.$request->maxprice.'" '; }
$dataWhere = implode(" and ",$where);
if($dataWhere != ""){
$properties = DB::table('property_list')
->join('users','users.id','=','property_list.user_id')
->join('property_room','property_room.property_id','=','property_list.id')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->whereRaw($dataWhere)
->get();
}else{
$properties = DB::table('property_list')
->join('users','users.id','=','property_list.user_id')
->join('property_room','property_room.property_id','=','property_list.id')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->get();
}
$property_type = $request->property_type - ONE;
$source_location = urlencode($request->formatted_address);
$nearby_properties = array();
$lat_lng = array();
foreach ($properties as $property) {
$dest_location = $property->location;
$destination_location = urlencode($property->location);
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins="
. $source_location . "&destinations=" . $destination_location .
"&key=" . GOOGLE_MAPS_API_KEY . "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response = json_decode($response);
//echo ; exit;
try {
if ($response->rows[0]->elements[0]->status != 'ZERO_RESULTS') {
$distance = (float) $response->rows[0]->elements[0]-
>distance->text;
if ($distance <= RADIUS) {
$property->location = $dest_location;
$property->property_id = $property->id;
$property->pricing = DB::table('property_images')->where('client_id',
CLIENT_ID)->where('property_id', $property->id)->first();
$property->images = DB::table('property_short_term_pricing')->where('client_id',
CLIENT_ID)->where('property_id', $property->id)->first();
$temp_status = ACTIVE;
if ($request->guests) {
if ($request->guests > $property->total_guests) {
$temp_status = BLOCK;
}
}
if ($request->from_date) {
$from_date = date('Y-m-d', strtotime($request->from_date));
$sql = "SELECT count(*) as count FROM `property_booking` WHERE '" . $from_date . "' between `start_date`
and `end_date` AND `property_id` = " . $property->id . "";
$query = DB::select($sql);
if ($query[0]->count > 0) {
$temp_status = BLOCK;
}
}
if ($request->to_date) {
$from_date = date('Y-m-d', strtotime($request->to_date));
$sql = "SELECT count(*) as count FROM `property_booking` WHERE '" . $from_date . "' between `start_date`
and `end_date` AND `property_id` = " . $property->id . "";
$query = DB::select($sql);
if ($query[0]->count > 0) {
$temp_status = BLOCK;
}
}
if ($temp_status == ACTIVE) {
$lat = (float) $property->lat;
$lng = (float) $property->lng;
$price_data = DB::table('property_short_term_pricing')
->where('client_id', CLIENT_ID)
->where('property_id', $property->id)->first();
$t = array('id' => $property->id, 'lat' => $lat, 'lng' => $lng, 'price' => $price_data->price_per_night);
$lat_lng[] = $t;
$nearby_properties[] = $property;
}else{
$nearby_properties[] = $property;
}
}
}
else{
$nearby_properties[] = $property;
}
} catch (\Exception $e) {
}
}
$nearby_properties = DB::table('property_list')
->join('users','users.id','=','property_list.user_id')
->join('property_room','property_room.property_id','=','property_list.id')
->join('property_short_term_pricing','property_short_term_pricing.property_id','=','property_list.id')
->where('property_list.client_id', '=', CLIENT_ID)
->where('property_list.is_complete', '=', ACTIVE)
->get();
foreach ($nearby_properties as $key => $value) {
$image = DB::table('property_images')->where('property_id',$value->property_id)->first();
$value->image_url = $image->image_url;
}
//echo json_encode($nearby_properties); exit;
$lat_lng_url = urlencode(serialize($lat_lng));
return view('owner.search_results')->with('properties', $nearby_properties)->with('location_url',
$lat_lng_url)->with('request_data', `$request->all());
}
}
Comments
Post a Comment