Phase 3 asset storage management
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
@props(['type', 'id', 'kind' => 'general'])
|
||||
|
||||
<form method="POST" action="{{ route('attachments.store') }}" enctype="multipart/form-data" class="mt-4 space-y-3 rounded border p-4">
|
||||
@php
|
||||
$maxMb = round(((int) config('provider-exchange.attachments.max_kb')) / 1024, 1);
|
||||
$mimeTypes = implode(', ', config('provider-exchange.attachments.allowed_mime_types'));
|
||||
@endphp
|
||||
|
||||
<form method="POST" action="{{ route('attachments.store') }}" enctype="multipart/form-data" class="mt-4 space-y-3 rounded-md border border-slate-200 bg-white p-4 dark:border-slate-800 dark:bg-slate-900">
|
||||
@csrf
|
||||
<input type="hidden" name="attachable_type" value="{{ $type }}">
|
||||
<input type="hidden" name="attachable_id" value="{{ $id }}">
|
||||
<input type="hidden" name="kind" value="{{ $kind }}">
|
||||
<x-field name="caption" label="Caption" />
|
||||
<input type="file" name="file" required class="block w-full text-sm">
|
||||
<div>
|
||||
<label for="file-{{ $type }}-{{ $id }}-{{ $kind }}" class="block text-sm font-medium text-slate-800 dark:text-slate-200">File</label>
|
||||
<input id="file-{{ $type }}-{{ $id }}-{{ $kind }}" type="file" name="file" required class="mt-1 block w-full text-sm text-slate-700 file:me-4 file:rounded-md file:border-0 file:bg-sky-600 file:px-3 file:py-2 file:text-sm file:font-semibold file:text-white hover:file:bg-sky-700 dark:text-slate-300">
|
||||
<p class="mt-1 text-xs text-slate-500 dark:text-slate-400">Max {{ $maxMb }} MB. Allowed: {{ $mimeTypes }}.</p>
|
||||
<x-input-error :messages="$errors->get('file')" class="mt-2" />
|
||||
</div>
|
||||
<x-primary-button>Upload file</x-primary-button>
|
||||
</form>
|
||||
|
||||
@@ -3,10 +3,33 @@
|
||||
@if ($attachments->count())
|
||||
<div class="mt-4 grid gap-3 md:grid-cols-2">
|
||||
@foreach ($attachments as $attachment)
|
||||
<a href="{{ asset('storage/'.$attachment->path) }}" class="block rounded border p-3 text-sm" target="_blank">
|
||||
<span class="font-semibold">{{ $attachment->original_name }}</span>
|
||||
<span class="block text-gray-500">{{ $attachment->caption }}</span>
|
||||
</a>
|
||||
<div class="rounded-md border border-slate-200 bg-white p-3 text-sm dark:border-slate-800 dark:bg-slate-900">
|
||||
@if ($attachment->isImage())
|
||||
<a href="{{ $attachment->publicUrl() }}" target="_blank" class="block overflow-hidden rounded-md border border-slate-200 dark:border-slate-800">
|
||||
<img src="{{ $attachment->publicUrl() }}" alt="{{ $attachment->caption ?: $attachment->original_name }}" class="h-36 w-full object-cover">
|
||||
</a>
|
||||
@endif
|
||||
<div class="{{ $attachment->isImage() ? 'mt-3' : '' }} flex items-start justify-between gap-3">
|
||||
<a href="{{ $attachment->publicUrl() }}" class="font-semibold text-sky-700 hover:text-sky-900 dark:text-sky-300 dark:hover:text-sky-200" target="_blank">
|
||||
{{ $attachment->original_name }}
|
||||
</a>
|
||||
@auth
|
||||
@if (auth()->id() === $attachment->user_id || auth()->user()->hasRole('admin'))
|
||||
<form method="POST" action="{{ route('attachments.destroy', $attachment) }}">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="text-xs font-semibold text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300">Delete</button>
|
||||
</form>
|
||||
@endif
|
||||
@endauth
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ $attachment->kind }} | {{ $attachment->mime_type ?: 'unknown type' }} | {{ $attachment->formattedSize() }}
|
||||
</p>
|
||||
@if ($attachment->caption)
|
||||
<p class="mt-2 text-slate-600 dark:text-slate-400">{{ $attachment->caption }}</p>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
Reference in New Issue
Block a user