authorize("{$functionName}-{$this->modulo}-{$this->funcionalidade}"); } protected 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 function getWhereFromQueryString(array $fields): array { $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 function addPaginationToQuery($builder, $perPage, $currentPage) { $numberOfRows = (int) $perPage; $rowsToSkip = ((int) $currentPage - 1) * $numberOfRows; $builder->skip($rowsToSkip)->take($numberOfRows); } protected function getDataTableResponseBody($totalRows, $collection) { return ['total_rows' => $totalRows, 'items' => $collection]; } protected function getCurrentLotacao() { return Lotacao::findOrFail(auth()->payload()->get('lotacao_id')); } protected function getCurrentCentroCusto() { return CentroCusto::findOrFail(auth()->payload()->get('centro_custo_id')); } }