I have the following code in my controller:
public function getBycountryCategory($country,$category)
{
$category = TourCategory::where('slug',$category)->first();
$country = Country::where('name','=',$country)->first();
$tours = $country->tours()->with('region')->get(['region_id']);
$regions = $tours->pluck('region')->unique();
return view('public.pages.region-list')
->withRegions($regions)
->withCategory($category)
->withCountry($country);
}
@foreach($regions as $region)
<div class="col-md-4">
<a href="{{ route('getByregion',[$category->slug,$region->slug]) }}">
<img src="{{ asset($region->image) }}" alt="">
<div class="location-item" style="background-image: url({{ asset($region->image) }});">
<div class="location-term">{{ucfirst(str_replace("-", " ", $region->name))}}</div>
</div>
</a>
</div>
@endforeach
The above code works perfectly in my local machine but in live server it returns the error message of Trying to get property 'image' of non-object
or anything I want to get from $region
. When I dump and die $region variable it shows all the attributes of the variable.
The only thing I couldn't understand is the code doesn't give any kind of error in local development server but gives in production server.