File manager - Edit - /var/www/html/portalHomolog/app/Http/Services/Sei/PontoFocalService.php
Back
<?php namespace App\Http\Services\Sei; use Illuminate\Support\Facades\DB; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use App\Models\Sei\PontoFocal; use App\Models\Structure; use \Illuminate\Contracts\Pagination\LengthAwarePaginator; class PontoFocalService { public function searchList(Request $request): LengthAwarePaginator { $paginate = 20; if ($request->filled('q')) { $request->validate(['q' => 'nullable|string|max:255']); $pontosFocais = PontoFocal::select('pontos_focais.*') ->join('structures', 'structures.id', '=', 'pontos_focais.structure_id') ->where(function ($query) use ($request) { $q = trim($request->q); $query->where('pontos_focais.nome', 'like', "%{$q}%") ->orWhere('pontos_focais.matricula', 'like', "%{$q}%") ->orWhere('pontos_focais.telefone_ramal', 'like', "%{$q}%") ->orWhere('pontos_focais.email', 'like', "%{$q}%") ->orWhere('structures.name', 'like', "%{$q}%"); }) ->orderByDesc('pontos_focais.created_at') ->paginate($paginate); } else { $pontosFocais = PontoFocal::with('instituicao')->orderBy('created_at', 'desc')->paginate($paginate); } return $pontosFocais; } public function getEstruturasAgrupadas(): array { $gabinetes = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO') ->whereIn('type', ['GABINETE_PREFIETURA', 'GABINETE_VICE_PREFIETURA']) ->orderBy('name', 'asc')->get(); $secretarias = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO')->where('type', 'SECRETARIA') ->orderBy('name', 'asc')->get(); $executivas = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO')->where('type', 'SECRETARIA_EXECUTIVA') ->orderBy('name', 'asc')->get(); $autarquias = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO')->whereIn('type', ['AUTARQUIA', 'FUNDACAO']) ->orderBy('name', 'asc')->get(); $superintendencias = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO')->where('type', 'SUPERINTENDENCIA') ->orderBy('name', 'asc')->get(); $diretorias = Structure::select('id', 'name', 'abbreviation', 'type') ->where('status', 'ATIVADO')->where('type', 'DIRETORIA') ->orderBy('name', 'asc')->get(); return compact('gabinetes', 'secretarias', 'executivas', 'autarquias', 'superintendencias', 'diretorias'); } public function store(array $data): RedirectResponse { try { DB::beginTransaction(); PontoFocal::create($data); DB::commit(); return redirect()->route('admin.pontosFocais.index') ->with('success', "* O ponto focal {$data['nome']} foi cadastrado com sucesso!"); } catch (\Exception $e) { DB::rollBack(); return redirect()->route('admin.pontosFocais.create') ->withInput() ->with('error', 'Erro ao tentar cadastrar este ponto focal. ' . $e->getMessage()); } } public function update(array $data, PontoFocal $pontoFocal, int $page = 1): RedirectResponse { try { DB::beginTransaction(); $pontoFocal->update($data); DB::commit(); return redirect()->route('admin.pontosFocais.index', ['page' => $page]) ->with('success', "* O ponto focal {$data['nome']} foi atualizado com sucesso!"); } catch (\Exception $e) { DB::rollBack(); return redirect()->route('admin.pontosFocais.edit', $pontoFocal->id) ->withInput() ->with('error', 'Erro ao tentar atualizar este ponto focal. ' . $e->getMessage()); } } public function destroy(PontoFocal $pontoFocal, int $page = 1): RedirectResponse { try { DB::beginTransaction(); PontoFocal::destroy($pontoFocal->id); DB::commit(); return redirect()->route('admin.pontosFocais.index', ['page' => $page]) ->with('success', "* O ponto focal {$pontoFocal->nome} foi excluído com sucesso! Esta ação não pode ser desfeita!"); } catch (\Exception $e) { DB::rollBack(); return redirect()->route('admin.pontosFocais.index', ['page' => $page]) ->withInput() ->with('error', 'Erro ao tentar excluir este ponto focal. ' . $e->getMessage()); } } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings