From 328a01e2a28bf9f055c89565c19a68b9ac3fd03c Mon Sep 17 00:00:00 2001 From: kolirt Date: Sun, 20 Oct 2024 15:27:02 +0300 Subject: [PATCH] add responseFile method --- composer.json | 2 +- src/Traits/MasterModel.php | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index e72c3b9..9153126 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "homepage": "https://github.com/kolirt/laravel-master-model", "license": "MIT", - "version": "4.0.2", + "version": "4.0.3", "authors": [ { "name": "kolirt" diff --git a/src/Traits/MasterModel.php b/src/Traits/MasterModel.php index 90ed8a8..36da5eb 100644 --- a/src/Traits/MasterModel.php +++ b/src/Traits/MasterModel.php @@ -312,19 +312,17 @@ private function getDisk($key = null): string return $this->upload_disks[$key] ?? config('master-model.files.disk'); } - /*private function hasUploadedFile(array $attributes): bool + public function responseFile(string $key, $name = null, array $headers = [], $disposition = 'inline') { - foreach ($attributes as $value) { - if ($value instanceof UploadedFile) { - return true; - } - } - return false; - }*/ + $value = $this->getAttributeValue($key); - public function getImage() - { + if (is_stored_file($value)) { + [$disk_name, $stored_file_path] = explode(':', $value); + return Storage::disk($disk_name)->response($stored_file_path, $name, $headers, $disposition); + } + abort(404); } + }