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();
}
}