File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/CustomerService/CustomerServiceService.php
<?php
namespace App\KommaApp\CustomerService;
use App\KommaApp\CustomerService\Models\CustomerService;
class CustomerServiceService
{
/**
* Fetch translated CustomerService routes
*
* @return object | bool
*/
public function getAllTranslatedCustomerServiceRoutes()
{
// Find all CustomerServices
if( ! $CustomerServices = CustomerService::where('active',1)
->where('lft', '!=', 1)
->orderBy('lft','asc')
->with('translation')
->with('translation.route')
->get()
) return false;
$routes = [];
// Loop through CustomerServices
foreach($CustomerServices as $key => $CustomerService)
{
if(isset($CustomerService->translation) && isset($CustomerService->translation->route)){
$routes[$CustomerService->code_name] = (object)[
'name' => $CustomerService->translation->name,
'route' => $CustomerService->translation->route->alias,
'node' => $CustomerService
];
}
}
return (object)$routes;
}
/**
* Get CustomerService by specific code name
*
* @param $codeName
* @return CustomerService
*/
public function getCustomerServiceByCodeName($codeName): CustomerService
{
if(!$CustomerService = CustomerService::where('code_name','=', $codeName)
->with('translation')
->where('active', 1)
->first()) \App::abort(404);
return $CustomerService;
}
}