loops - Show a collection in laravel from controller on different columns in view -
got problem:
i want show info collection publication has "featured" column in true.
$pub_destacadas = publicaciones::take(3)->where('destacado', '=', 1)->get();
the problem layout has 3 elements fill information have different sizes wasn't able solve using chunk() method in foreach in blade template, tried following:
$individual_destacada = $pub_destacadas->take(1); $grupo_destacada = $pub_destacadas->take(2);
and show them in view follows:
<div class="publicaciones-destacadas"> <div class="container"> <h2>publicaciones destacadas</h2> <div class="row"> @foreach($individual_destacada $destacada) <div class="col-md-6"> <div class="item-destacado size-2"> <img class="img-responsive" src="{{ asset('img/publicaciones/' . $destacada->imagen ) }}"> {{ $destacada->titulo }} {{ $destacada->descripcion }} </div> </div> @endforeach <div class="col-md-6"> @foreach($grupo_destacada $destacada) <div class="row doble-publicacion"> <div class="col-md-12"> <div class="item-destacado size-1"> <img class="img-responsive" src="{{ asset('img/publicaciones/' . $destacada->imagen ) }}"> {{ $destacada->titulo }} {{ $destacada->descripcion }} </div> </div> </div> @endforeach </div> </div> </div> </div>
so... shows correctly in layout first item query gets shown 2 times in layout. how can exclude first element in second variable featured publications?
hope explained problem correctly.
you can use splice.
$individual_destacada = $pub_destacadas->splice(1); $grupo_destacada = $pub_destacadas->splice(2);
Comments
Post a Comment