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