1
私はlaravel 5.3を使ってWebアプリケーションを開発していますが、問題が1つあります。Laravelでこの配列をループする方法は?
この配列をループしたいです。私が試した何
は次のとおりです。
コントローラー:
public function postSearch(Request $request)
{
$categoryid = $request->category_id;
$locationid = $request->location_id;
$category = Category::where('id', $categoryid)->first();
$cities = Location::where('id', $locationid)->pluck('city');
$cityname = $cities[0];
$alllocations = [];
$ratecards = [];
$locations = [];
$father = [];
$i = 0;
$filteredlocations = $category->locations->where('city', $cityname)->all();
foreach($filteredlocations as $location){
$alllocations[$i] = $location->getaddetails;
$ratecards[$i] = $location->ratecard;
$i++;
}
$father[0] = $alllocations;
$father[1] = $ratecards;
return view('ads', compact('father'));
}
ビューはここにある:
@foreach($father as $key => $f)
@foreach($f as $key => $arr)
@if (isset($arr->adName))
<div class="post">
{{Html::image($arr->path,'Ad Picture',array('class' => 'ad-image'))}}
<a href="{{ url('ads', $arr->location_id) }}"><h2 class="post-title">{{ $arr->adName }}</h2></a>
<p class="description">{{ $arr->description }} </p>
<div class="post-footer">
<span class="categories">
<ul class="cats">
<li class="btn btn-default">Price :
{{ $f[$key]->monthly_rate }}
</li>
<li class="btn btn-default">Status:
@if($arr->status == 1)
<p>Active</p>
@else
<p>Not-Active</p>
@endif
</li>
<li><a href="{{ url('ads', $arr->location_id) }}" class="details-page">view details</a></li>
</ul>
</span>
</div>
</div>
@endif
@endforeach
@endforeach
問題:
問題は、第2の配列{{ $f[$key]->monthly_rate }}
を取得しようとしたときです。RateCards何も得られません。 レートカードの配列を取得し、そこのフィールドである配列mothly_rate
を取得したいと考えています。
おかげ
PS:ビューで{{ $f[$key]->monthly_rate }}
この戻りナッシング。
このエラーが発生しました。非オブジェクトのプロパティを取得しようとしています。 – Alien