⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
PostalRepository.php
<?php namespace App\Repositories; use App\Models\Postal; use Exception; use Illuminate\Support\Facades\Route; // use Route; use Storage; use Str; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class PostalRepository */ class PostalRepository extends BaseRepository { /** * @var string[] */ protected $fieldSearchable = [ 'from_title', 'to_title', 'reference_no', 'date', 'address', ]; /** * @return array|string[] */ public function getFieldsSearchable() { return $this->fieldSearchable; } public function model(): string { return Postal::class; } public function store($input): bool { try { /** * @var Postal $postal */ $postal = $this->create($input); if (! empty($input['attachment'])) { $fileName = Route::current()->getName() == 'receives.store' ? 'Receive' : 'Dispatch'; $fileExtension = getFileName($fileName, $input['attachment']); $postal->addMedia($input['attachment'])->usingFileName($fileExtension)->toMediaCollection(Postal::PATH, config('app.media_disc')); } return true; } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function updatePostal(array $input, int $postalId) { try { /** * @var Postal $postal */ $postal = $this->update($input, $postalId); if (! empty($input['attachment'])) { $postal->clearMediaCollection(Postal::PATH); $fileName = Route::current()->getName() == 'receives.update' ? 'Receive' : 'Dispatch'; $fileExtension = getFileName($fileName, $input['attachment']); $postal->addMedia($input['attachment'])->usingFileName($fileExtension)->toMediaCollection(Postal::PATH, config('app.media_disc')); } if ($input['avatar_remove'] == 1 && isset($input['avatar_remove']) && ! empty($input['avatar_remove'])) { removeFile($postal, Postal::PATH); } } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function deleteDocument(int $postalId) { try { /** * @var Postal $postal */ $postal = $this->find($postalId); $postal->clearMediaCollection(Postal::PATH); $this->delete($postalId); } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function downloadMedia($postal): array { try { $documentMedia = $postal->media()->first(); $documentPath = $documentMedia->getPath(); if (config('app.media_disc') === 'public') { $documentPath = (Str::after($documentMedia->getUrl(), '/uploads')); } ob_end_clean(); $file = Storage::disk(config('app.media_disc'))->get($documentPath); $headers = [ 'Content-Type' => $postal->media[0]->mime_type, 'Content-Description' => 'File Transfer', 'Content-Disposition' => "attachment; filename={$postal->media[0]->file_name}", 'filename' => $postal->media[0]->file_name, ]; return [$file, $headers]; } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } }