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/SBogers10/komma.pro/app/KommaApp/Services/ServiceService.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 18/05/17
 * Time: 22:02
 */

namespace App\KommaApp\Services;
use App\KommaApp\Services\Models\Service;
use App\KommaApp\Services\Models\ServiceTranslation;
use Illuminate\Support\Facades\Cache;

class ServiceService
{
    private $services = [];

    /**
     * Get all services
     */
//    public function all()
//    {
//        if(empty($this->services))
//            $this->services = Cache::remember('services',1440,function(){
//               return Service::all();
//            });
//
//        return $this->services;
//    }

    public function all()
    {
        return Service::with('translation')
            ->has('translation')
            ->where('active', 1)
            ->where('show_in_menu', 1)
            ->orderBy('lft')
            ->get();
    }

    /**
     * Return service by slug
     *
     * @param $slug
     */
    public function serviceBySlug($slug)
    {
//        return Cache::remember('service.' . $slug,1440,function() use ($slug)
//        {
//            return Service::where('slug',$slug)->first();
//        });
        $serviceTranslation = ServiceTranslation::where('slug', $slug)->first();

        $service = Service::where('id', $serviceTranslation->service_id)
            ->where('active', 1)
            ->with('translation')
            ->has('translation')
            ->first();

        return $service;
    }

    public function nextService(Service $service)
    {
        $nextService = Service::where('active', 1)
            ->where('show_in_menu', 1)
            ->where('lft', '>', $service->lft)
            ->with('translation')
            ->has('translation')
            ->orderBy('lft')
            ->first();

        return $nextService;
    }

//    /**
//     * Return next service by current slug
//     *
//     * @param $slug
//     */
//    public function nextServiceBySlug($slug)
//    {
//        // Get current service
//        $currentService = $this->serviceBySlug($slug);
//
//        // Find next service by next id
//        // Todo: refactor when data comes from KMS
//        return Cache::remember('nextService.' . $slug,1440,function() use ($currentService)
//        {
//            return Service::where('id','>',$currentService->id)->first();
//        });
//    }
}