File: D:/HostingSpaces/SBogers10/arborconsulting.komma.pro/app/KommaApp/Services/ServiceService.php
<?php
namespace App\KommaApp\Services;
use App\KommaApp\Services\Models\Service;
use Carbon\Carbon;
class ServiceService
{
private $today;
public function __construct()
{
$this->today = Carbon::now()->addHour();
$this->today = $this->today->format('Y-m-d H:i:s');
}
public function getAllServices($pagination = false, $itemsPerPage = 9)
{
$services = \App::getSite()
->services()
->with('translation', 'images')
->where('active', 1)
->where('lft', '!=', 1)
->orderBy('lft','asc');
if($pagination)
{
$services = $services->paginate($itemsPerPage);
}
else
{
$services = $services->get();
}
return $services;
}
/**
* Fetch translated page routes
*
* @return object | bool
*/
public function getAllTranslatedServiceRoutes($serviceRoute, &$links)
{
if(!\App::getSite()) return false;
// Find all pages
if( ! $services = \App::getSite()
->services()
->with('translation', 'images')
->where('active', 1)
->where('lft', '!=', 1)
->orderBy('lft','asc')
->get()
) return null;
// Loop through pages
foreach($services as $key => $service)
{
if(isset($service->translation)){
$links->{$service->code_name} = (object)[
'name' => $service->translation->name,
'route' => $serviceRoute. '/' .$service->translation->slug,
'node' => $service
];
}
}
}
}