File manager - Edit - /var/www/html/portalHomolog/app/Http/Services/RHInformativoService.php
Back
<?php namespace App\Http\Services; use App\Models\RHInformativo; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Http\Request; class RHInformativoService { public function listWithFilters(Request $request, int $perPage = 50): LengthAwarePaginator { $request->validate([ 'q' => 'nullable|string|max:255', 'categoria' => 'nullable|string|max:255', 'dataPublicacao' => 'nullable|date', 'numero' => 'nullable|string|max:255', 'tipo' => 'nullable|string|max:255', 'descricao' => 'nullable|string|max:5000', ]); $temFiltro = $request->filled('q') || $request->filled('categoria') || $request->filled('dataPublicacao') || $request->filled('numero') || $request->filled('tipo') || $request->filled('descricao'); if (!$temFiltro) { return RHInformativo::orderByDesc('categoria') ->orderByDesc('dataPublicacao') ->paginate($perPage); } return RHInformativo::query() ->when($request->filled('categoria'), fn ($q) => $q->where('categoria', $request->categoria)) ->when($request->filled('dataPublicacao'), fn ($q) => $q->whereDate('dataPublicacao', $request->dataPublicacao)) ->when($request->filled('numero'), fn ($q) => $q->where('numero', 'like', '%' . trim($request->numero) . '%')) ->when($request->filled('tipo'), fn ($q) => $q->where('tipo', 'like', '%' . trim($request->tipo) . '%')) ->when($request->filled('descricao'), fn ($q) => $q->where('descricao', 'like', '%' . trim($request->descricao) . '%')) ->when($request->filled('q'), function ($query) use ($request) { $q = trim($request->q); $query->where(function ($sub) use ($q) { $sub->where('categoria', 'like', "%{$q}%") ->orWhere('numero', 'like', "%{$q}%") ->orWhere('tipo', 'like', "%{$q}%") ->orWhere('descricao', 'like', "%{$q}%"); }); }) ->orderByDesc('categoria') ->orderByDesc('dataPublicacao') ->paginate($perPage); } public function create(array $data): RHInformativo { return RHInformativo::create($data); } public function update(RHInformativo $informativo, array $data): RHInformativo { $informativo->update($data); return $informativo; } public function delete(RHInformativo $informativo): void { $informativo->delete(); } public function updateStatus(RHInformativo $informativo, string $status): RHInformativo { $informativo->update(['status' => $status]); return $informativo; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings