File: D:/HostingSpaces/SBogers10/kemi.komma.pro/app/KommaApp/Machines/MachineService.php
<?php
namespace App\KommaApp\Machines;
use App\KommaApp\Machines\Models\Machine;
use App\KommaApp\Pages\Models\Page;
use Carbon\Carbon;
class MachineService
{
public function getMachineTypes()
{
$productionPage = Page::where('code_name', 'production')->first();
$productionPages = Page::where('lft', '>', $productionPage->lft)
->where('lft', '<', $productionPage->rgt)
->with('translation')
->where('active', 1)
->get();
$machineTypes = [];
foreach ($productionPages as $productionPage){
$machineTypes[] = $productionPage->code_name;
}
return $machineTypes;
}
public function getFullMachineTypes()
{
$machineTypes = $this->getMachineTypes();
// Manually add measure because it isn't a subpage of production
$machineTypes[] = 'measure';
$machines = [];
foreach ($machineTypes as $machineType){
$typeMachines = $this->getMachinesByType($machineType);
if($typeMachines->count() != 0)
$machines[$machineType] = ['title' => trans('site/machinepark.'.$machineType), 'machines' => $typeMachines];
}
return $machines;
}
public function getMachinesByType($type){
$machines = Machine::where('active', '1')
->where('type', '=', $type)
->with('translation')
->has('translation')
->get();
return $machines;
}
}