Php 试图获得财产';图像';非对象拉威尔的研究
我的控制器中有以下代码:Php 试图获得财产';图像';非对象拉威尔的研究,php,laravel,laravel-5.5,Php,Laravel,Laravel 5.5,我的控制器中有以下代码: public function getBycountryCategory($country,$category) { $category = TourCategory::where('slug',$category)->first(); $country = Country::where('name','=',$country)->first(); $tours = $country->tours()->with(
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
公共函数getBycountryCategory($country,$category)
{
$category=TourCategory::where('slug',$category)->first();
$country=country::其中('name','=',$country)->first();
$tours=$country->tours()->with('region')->get(['region_id']);
$regions=$tours->pull('region')->unique();
返回视图(“public.pages.region列表”)
->withRegions($regions)
->withCategory($category)
->withCountry($国家);
}
@foreach($regions作为$region)
@endforeach
上面的代码在我的本地机器上运行得很好,但在live server中,它返回了一条错误消息,试图获取非对象
的属性“image”或我想从$region
获取的任何内容。当我转储并死亡$region变量时,它会显示该变量的所有属性
我唯一不能理解的是,代码在本地开发服务器中没有给出任何错误,但在生产服务器中给出了错误。您好,您能检查一下这是否有效吗$regions=$tours->pull('region')->unique()->first()@ashish我发现了错误。集合中的null是导致错误的原因。