File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Testimonials/TestimonialComposer.php
<?php
/**
* Created by PhpStorm.
* User: mikevandersanden
* Date: 16/10/2017
* Time: 20:36
*/
namespace App\KommaApp\Testimonials;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class TestimonialComposer
{
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
// Count all testimonials
$testimonialCount = count(Config::get('site.testimonials'));
// Setup logo groups
$clientLogoGroups = collect([]);
$clientLogoGroup = [];
$remainingClientLogos = [];
// Loop through the config settings
// Add groups for as long as there are testimonials
// Put the rest in the logo
foreach(Config::get('site.clients') as $key => $client) {
// See if we still need groups
if ($clientLogoGroups->count() < $testimonialCount)
{
// Add client to a group
$clientLogoGroup[] = $client;
// When the group is full, push the group in the collection
if (($key + 1) % 6 == 0) {
$clientLogoGroups->push($clientLogoGroup);
// Reset the group
$clientLogoGroup = [];
continue;
}
}
// Rest of the logo's below the testimonials
else{
$remainingClientLogos[] = $client;
}
}
$view->with([
'clientLogoGroups' => $clientLogoGroups,
'remainingClientLogos' => $remainingClientLogos
]);
}
}