File manager - Edit - /var/www/html/portalHomolog/app/Http/Controllers/Comunicacao/BannersController.php
Back
<?php namespace App\Http\Controllers\Comunicacao; use App\Http\Controllers\Controller; use App\Models\Comunicacao\Banner; use App\Http\Requests\Comunicacao\BannerRequest; use App\Http\Services\Comunicacao\BannerService; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; use App\Helpers\FileUploadHelper; class BannersController extends Controller { private $permissao = "GERENCIADOR_DE_BANNERS"; public function index(Request $request): View|LengthAwarePaginator|RedirectResponse { $response = $this->checkPermissao($this->permissao, "visualizar"); if ($response instanceof RedirectResponse) { return $response; } $BannerService = new BannerService(); $banners = $BannerService->index($request); return view("admin.banners.index", compact(['banners'])); } public function create(): View|RedirectResponse { $response = $this->checkPermissao($this->permissao, "adicionar"); if ($response instanceof RedirectResponse) { return $response; } return view("admin.banners.create"); } public function store(BannerRequest $request): RedirectResponse { $response = $this->checkPermissao($this->permissao, "adicionar"); if ($response instanceof RedirectResponse) { return $response; } $request->validated(); $request->validated(); $ds = DIRECTORY_SEPARATOR; $path = "pmar/assets/img/icons/photoLG-940x130px.png"; $pathMD = null; $pathSM = null; if ($request->hasFile('photo') && $request->file('photo')->isValid()) { $file = $request->file('photo'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $path = $uploadedPath; } } if ($request->hasFile('photoMD') && $request->file('photoMD')->isValid()) { $file = $request->file('photoMD'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $pathMD = $uploadedPath; } } if ($request->hasFile('photoSM') && $request->file('photoSM')->isValid()) { $file = $request->file('photoSM'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $pathSM = $uploadedPath; } } $array_banner = [ 'title' => $request->title, 'url' => $request->url, 'photo' => $path, 'photoMD' => $pathMD, 'photoSM' => $pathSM, 'order' => $request->order ?? 0, 'section' => $request->section, 'target' => $request->target, 'status' => $request->status, ]; $BannerService = new BannerService(); return $BannerService->store($request, $array_banner); } public function edit(Banner $banner): View|RedirectResponse { $response = $this->checkPermissao($this->permissao, "editar"); if ($response instanceof RedirectResponse) { return $response; } if (!$banner) { return redirect("/admin/banners") ->with("error", __("Banner não encontrado.")); } return view('admin.banners.edit', compact('banner')); } public function update(BannerRequest $request, Banner $banner): RedirectResponse { $response = $this->checkPermissao($this->permissao, "editar"); if ($response instanceof RedirectResponse) { return $response; } $request->validated(); $ds = DIRECTORY_SEPARATOR; $array_banner = [ 'title' => $request->title, 'url' => $request->url, 'order' => $request->order ??= 0, 'section' => $request->section, 'target' => $request->target, 'status' => $request->status, ]; $path = $banner->photo; $pathMD = null; $pathSM = null; if ($request->hasFile('photo')) { if ($banner->photo != "pmar/assets/img/icons/photoLG-940x130px.png") { $search = "pmar{$ds}assets{$ds}img"; $file_exist = storage_path() . str_replace($search, "{$ds}app{$ds}public", $banner->photo); if (@file_exists($file_exist)) { unlink($file_exist); } } $file = $request->file('photo'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $path = $uploadedPath; } } if ($request->hasFile('photoMD')) { if ($banner->photoMD != "pmar/assets/img/icons/photoMD-720x100px.png" && $banner->photoMD != null) { $search = "pmar{$ds}assets{$ds}img"; $file_exist = storage_path() . str_replace($search, "{$ds}app{$ds}public", $banner->photoMD); if (@file_exists($file_exist)) { unlink($file_exist); } } $file = $request->file('photoMD'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $pathMD = $uploadedPath; } } if ($request->hasFile('photoSM')) { if ($banner->photoSM != "pmar/assets/img/icons/photoSM-1080x1350px.png" && $banner->photoSM != null) { $search = "pmar{$ds}assets{$ds}img"; $file_exist = storage_path() . str_replace($search, "{$ds}app{$ds}public", $banner->photoSM); if (@file_exists($file_exist)) { unlink($file_exist); } } $file = $request->file('photoSM'); $uploadedPath = FileUploadHelper::processSafeImageUpload($file, 'banners'); if ($uploadedPath) { $pathSM = $uploadedPath; } } $array_banner['photo'] = $path; $array_banner['photoMD'] = $pathMD; $array_banner['photoSM'] = $pathSM; $BannerService = new BannerService(); return $BannerService->update($request, $banner, $array_banner); } public function destroy(Request $request, Banner $banner): RedirectResponse { $response = $this->checkPermissao($this->permissao, "excluir"); if ($response instanceof RedirectResponse) { return $response; } $ds = DIRECTORY_SEPARATOR; if ($banner->photo != "pmar/assets/img/icons/photoLG-940x130px.png") { $search = "pmar{$ds}assets{$ds}img"; $file_exist = storage_path() . str_replace($search, "{$ds}app{$ds}public", $banner->photo); if (@file_exists($file_exist)) { unlink($file_exist); } } $BannerService = new BannerService(); return $BannerService->destroy($request, $banner); } public function status(Request $request, Banner $banner): RedirectResponse { $response = $this->checkPermissao($this->permissao, "editar"); if ($response instanceof RedirectResponse) { return $response; } $BannerService = new BannerService(); return $BannerService->status($request, $banner); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings