File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Komma/Crews/CrewComposer.php
<?php
namespace App\Komma\Crews;
use App\Komma\Crews\Models\Crew;
use App\Komma\PricingProducts\Models\PricingProduct;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\App;
class CrewComposer
{
/**
* Bind data to the view.
*
* @param View $view
* @return View
*/
public function compose(View $view)
{
$packages = Crew::with('translation')
->join('crew_translations', 'crews.id', '=', 'crew_translations.crew_id')
->select('crews.*', 'crew_translations.active', 'crew_translations.language_id')
->where(function ($query) {
$query->where('active', '=', 1)
->where('language_id', '=', App::getLanguage()->id);
})
->has('translation')
->get();
$masterArray = $this->generateMasterArray($packages);
$extraProducts = PricingProduct::whereIn('id', [5])->with('translation')->get();
$coreProduct = PricingProduct::where('id', 6)->with('translation')->get();
return $view->with(['packages' => $packages, 'masterArray' => $masterArray, 'additionalProducts' => $extraProducts, 'coreProduct' => $coreProduct]);
}
/**
* @param $packages
* @return array
*
* Combine all package labels to one array with all unique labels
*/
public function generateMasterArray($packages)
{
$array = [];
foreach ($packages as $package) {
foreach ($package->pricingLabels as $label) {
if (! isset($label->translation)) {
continue;
}
$array[] = $label->translation->name;
}
}
return array_unique($array);
}
}