init commit
All checks were successful
build-api-image / build (push) Successful in 51s

This commit is contained in:
Antonio Lopes dos Santos
2026-08-04 16:52:02 -03:00
commit afec302c3e
11594 changed files with 1636728 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Services;
use App\Models\Cadastro\Estabelecimento\CentroCusto;
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
abstract class Service
{
protected static function get($model, $id = null)
{
$model = $model::query();
$query = request()->query();
if (isset($query['with'])) {
$with = is_array($query['with']) ? $query['with'] : [$query['with']];
foreach ($with as $value) {
$model->with($value);
}
}
return is_null($id) ? $model : $model->findOrFail($id);
}
protected static function getWhereFromQueryString($fields)
{
$where = [];
foreach ($fields as $field) {
$operator = '';
$fld = $field;
if (is_array($field)) {
$fld = $field[0];
$operator = $field[1];
}
$query = request()->query();
if (!array_key_exists($fld, $query)) {
continue;
}
$vlr = $query[$fld];
if ($vlr === 'true') $vlr = 1;
if ($vlr === 'false') $vlr = 0;
if ($vlr === 'null') $vlr = null;
$fld = $fld === 'not_id' ? 'id' : $fld;
if ($operator === "")
$where[] = [$field, $vlr];
else
$where[] = [$fld, $operator, $vlr];
}
return $where;
}
protected static function getCurrentLotacao()
{
return auth()->check() ? Lotacao::findOrFail(auth()->payload()->get('lotacao_id')) : null;
}
protected static function getCurrentCentroCusto()
{
return auth()->check() ? CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id')) : null;
}
}