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/stafa.komma.pro/app/Komma/Departments/DepartmentService.php
<?php


namespace App\Komma\Departments;


use App\Komma\Base\Service;
use App\Komma\Departments\Models\Department;
use Carbon\Carbon;

final class DepartmentService extends Service
{

    private $today;

    public function __construct()
    {
        $this->today = now()->endOfDay();
        $this->today = $this->today->format('Y-m-d H:i:s');
        parent::__construct();
    }

    /**
     * Base query for get department from DB
     *
     * @return Department|\Illuminate\Database\Eloquent\Builder
     */
    public function baseDepartmentQuery()
    {
        return Department::where('active', 1)
            ->with('translation');
    }

    public function getDepartmentsWithEmployees()
    {
        $query = $this->baseDepartmentQuery();
        $query = $query->orderBy('lft', 'asc')
            ->with('employees','employees.images', 'employees.translation');
        return $query->get();
    }

    /**
     * Get all departments
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    public function getDepartments()
    {
        return $this->baseDepartmentQuery()->get();
    }

    /**
     * Get $amount of latest departments
     *
     * @param  int  $amount
     * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
     */
    public function getLatestDepartment($amount = 3)
    {
        return $this->baseDepartmentQuery()
            ->take($amount)
            ->get();
    }


}