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/rentman2019.komma.pro/app/Komma/WebinarTags/WebinarTagService.php
<?php

namespace App\Komma\WebinarTags;

use App\Komma\Base\Service;
use Illuminate\Database\Eloquent\Collection;

final class WebinarTagService extends Service
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * return all webinar tags with webinars
     *
     * @return Collection
     */
    public function getAllWebinarTags(): Collection
    {
        $tags = $this->site
            ->webinarTags()
            ->with('translation', 'webinars')
            ->where('active', '=', 1)
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'desc')
            ->get();

        foreach ($tags as $tag) {
            if ($tag->id !== 2) {
                $tag->webinars = $tag->webinars->sortBy('lft');
            }
            if ($tag->id === 2) {
                $tag->webinars = $tag->webinars->sortByDesc(function ($obj, $key) {
                    return $obj->created_at->getTimeStamp();
                });
            }
        }

        return $tags;
    }
}