wip attachments
This commit is contained in:
parent
8d74373ad0
commit
e6376c7d92
@ -20,19 +20,20 @@ public function upload(Request $request)
|
||||
]);
|
||||
|
||||
foreach ($request->file('file') as $file) {
|
||||
$study->addMedia($file)->toMediaCollection('uploads');
|
||||
$study->addMedia($file)->toMediaCollection(Study::MEDIA_COLLECTION);
|
||||
}
|
||||
|
||||
return response()->json(['success' => 'Files uploaded successfully']);
|
||||
}
|
||||
|
||||
public function delete($mediaId)
|
||||
public function delete(string $hashId, int $mediaId)
|
||||
{
|
||||
abort_unless(auth()->user()->may(Permission::AttachmentUpload), 403);
|
||||
$this->decodeKeys();
|
||||
$study = Study::findOrFail($this->key);
|
||||
$media = $study->getMedia('uploads')->where('id', (int) $mediaId)->first();
|
||||
if ($media) {
|
||||
$media = $study->getMedia(Study::MEDIA_COLLECTION)->where('id', $mediaId)->first();
|
||||
|
||||
if ($media !== null) {
|
||||
$media->delete();
|
||||
|
||||
return redirect()->back()->with('success', 'File deleted successfully');
|
||||
|
@ -21,6 +21,8 @@ class Study extends BaseModel implements HasMedia
|
||||
use HashableId;
|
||||
use InteractsWithMedia;
|
||||
|
||||
public const string MEDIA_COLLECTION = 'attachments';
|
||||
|
||||
public function details(): HasOne
|
||||
{
|
||||
return $this->hasOne(StudyDetails::class);
|
||||
|
@ -54,8 +54,8 @@
|
||||
|
||||
Dropzone.options.fileDropzone = {
|
||||
paramName: 'file',
|
||||
maxFilesize: 2, // MB
|
||||
acceptedFiles: '.pdf,.jpg,.png',
|
||||
maxFilesize: 5, // MB
|
||||
acceptedFiles: '.pdf,.jpg,.jpeg,.png',
|
||||
uploadMultiple: true,
|
||||
parallelUploads: 3,
|
||||
headers: {
|
||||
@ -117,7 +117,7 @@
|
||||
<div class="uploaded-files">
|
||||
<h2>Uploaded Files</h2>
|
||||
<ul>
|
||||
@foreach ($study->getMedia('uploads') as $media)
|
||||
@foreach ($study->getMedia(\App\Models\Study::MEDIA_COLLECTION) as $media)
|
||||
<li>
|
||||
<i class="fa {{ $media->mime_type == 'application/pdf' ? 'fa-file-pdf' : 'fa-file-image' }}"></i>
|
||||
<a href="{{ $media->getUrl() }}" target="_blank">{{ $media->file_name }}</a>
|
||||
|
@ -62,7 +62,7 @@
|
||||
<div class="uploaded-files">
|
||||
<h2>Uploaded Files</h2>
|
||||
<ul>
|
||||
@foreach ($study->getMedia('uploads') as $media)
|
||||
@foreach ($study->getMedia(\App\Models\Study::MEDIA_COLLECTION) as $media)
|
||||
<li>
|
||||
<i class="fa {{ $media->mime_type == 'application/pdf' ? 'fa-file-pdf' : 'fa-file-image' }}"></i>
|
||||
<a href="{{ $media->getUrl() }}" target="_blank">{{ $media->file_name }}</a>
|
||||
|
Loading…
Reference in New Issue
Block a user