This commit is contained in:
Dr Masroor Ehsan 2025-01-07 02:19:51 +06:00
parent 18981e8cf1
commit 1b48d3d719
4 changed files with 28 additions and 4 deletions

View File

@ -5,7 +5,9 @@
use App\Http\Controllers\HashidControllerBase;
use App\Models\Enums\Permission;
use App\Models\Study;
use App\Services\AuditTrail\Activity;
use Illuminate\Http\Request;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class AttachmentController extends HashidControllerBase
{
@ -23,6 +25,11 @@ public function upload(Request $request)
$study->addMedia($file)->toMediaCollection(Study::MEDIA_COLLECTION);
}
audit()
->did(Activity::Attachment_Upload)
->on($this->key)
->log();
return response()->json(['success' => 'Files uploaded successfully']);
}
@ -36,9 +43,22 @@ public function delete(string $hashId, int $mediaId)
if ($media !== null) {
$media->delete();
audit()
->did(Activity::Attachment_Delete)
->on($this->key)
->log();
return redirect()->back()->with('success', 'File deleted successfully');
}
return redirect()->back()->with('error', 'File not found');
}
public function view(string $uuid)
{
$media = Media::findByUuid($uuid);
abort_if($media === null, 404);
return response()->file($media->getPath());
}
}

View File

@ -22,6 +22,9 @@ final class Activity
public const int Study_Archived = 108;
public const int Study_Delete = 109;
public const int Attachment_Upload = 110;
public const int Attachment_Download = 111;
public const int Attachment_Delete = 112;
// report

View File

@ -20,14 +20,14 @@
<div class="d-flex justify-content-start align-items-center">
<div class="avatar-wrapper">
<div class="avatar me-2">
<a target="_blank" href="{{ $media->getUrl() }}">
<a target="_blank" href="{{ route('staff.attachment.view', $media->uuid) }}">
<img class="rounded" src="{{ thumb_url($media) }}"/>
</a>
</div>
</div>
<div class="d-flex flex-column">
<a data-bs-popper="{{ $media->file_name }}" class="text-heading fw-medium" target="_blank"
href="{{ $media->getUrl() }}">
href="{{ route('staff.attachment.view', $media->uuid) }}">
{{ chomp($media->file_name, 20) }}
</a>
</div>

View File

@ -71,8 +71,9 @@
});
Route::group(['prefix' => 'attachment', 'as' => 'attachment.'], function () {
Route::post('upload/{hashid}', [AttachmentController::class, 'upload'])->name('upload');
Route::delete('delete/{hashid}/{media}', [AttachmentController::class, 'delete'])->name('delete');
Route::get('{uuid}', [AttachmentController::class, 'view'])->name('view');
Route::post('{hashid}', [AttachmentController::class, 'upload'])->name('upload');
Route::delete('{hashid}/{media}', [AttachmentController::class, 'delete'])->name('delete');
});
Route::group(['prefix' => 'meta', 'as' => 'meta.'], function () {