HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }
}