我怎样才能确保在我的刀片中使用更多的foreach,而不会重复多次内容?
$review = Review::orderBy('created_at', 'desc')->paginate(9);
$info_games = array();
$games = array();
foreach ($review as $value) {
$info_games[] = InfoGames::where('id_game', $value->id_game)->first();
$games[] = Games::where('id', $value->id_game)->first();
}
return view('front.pages.review.list', compact('review','info_games','games'));
和我的刀片:
@foreach ($review as $value)
@foreach ($info_games as $info_game)
<div>
<img src="https://gamelite.net/{{$info_game->image}}">
<p>{!! str_limit($value->body, 150) !!}</p>
</div>
@endforeach
@endforeach
{!! $review->render() !!}
答案 0 :(得分:0)
使用array_filter($ array)。它将返回唯一。 在你的情况下
$info_games = array_filter($info_games);