Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Assets: Multiple file uploads #951

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions app/Http/Controllers/Entity/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,11 @@ protected function storeFile(StoreEntityAsset $request, Campaign $campaign, Enti
$files = $service
->entity($entity)
->campaign($campaign)
->upload($request, 'file');

if (count($files) > 1) {
return redirect()
->route('entities.entity_assets.index', [$campaign, $entity])
->with('success', __('entities/files.create.success_plural', ['count' => count($files)]));
}
->upload($request, 'files');

return redirect()
->route('entities.entity_assets.index', [$campaign, $entity])
->with('success', __('entities/files.create.success', ['file' => $files[0]]));
->with('success', trans_choice('entities/files.create.success_plural', count($files), ['count' => count($files), 'name' => $files['0']]));
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved

} catch (TranslatableException $e) {
return redirect()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/StoreEntityAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function rules()
return $this->clean([
'name' => 'required_unless:type_id,' . EntityAsset::TYPE_FILE . '|max:45',
'visibility_id' => 'nullable|integer|exists:visibilities,id',
'file.*' => [
'files.*' => [
'required_if:type_id,' . EntityAsset::TYPE_FILE,
'file',
'max:' . Limit::upload(),
Expand Down
3 changes: 1 addition & 2 deletions lang/en/entities/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
'premium' => 'Uploading more files requires a premium campaign.',
],
'create' => [
'success' => 'File :file added.',
'success_plural' => 'Added :count files.',
'success_plural' => '{1} File :name added.|[2,*] :count files added.',
'title' => 'New file for :entity',
],
'destroy' => [
Expand Down
4 changes: 2 additions & 2 deletions resources/api-docs/1.0/entity-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ To create an asset, use the following endpoint.
| :- | :- | :- |
| `name` | `string` | The name of the asset (max 45) |
| `type_id` | `int` (Required) | The type of asset being created.
| `file` | `file` | The file to be uploaded as an asset, exlcusive and required for file assets (`type_id: 1`). |
| `files` | `file` | The file or files to be uploaded as an asset/assets, exclusive and required for file assets (`type_id: 1`). |
| `visibility_id` | `int` | The visibility id: 1 `all`, 2 `self`, 3 `admin`, 4 `self-admin` or 5 `members`. |
| `metadata` | `array` | `metadata.icon` and `metadata.url` are required for `links`. |
| `is_pinned` | `bool` | Controls wether or not an asset is shown and linked to on the pins tab in the overview of the entity, exlcusive to file assets (`type_id: 1`). |
| `is_pinned` | `bool` | Controls wether or not an asset is shown and linked to on the pins tab in the overview of the entity, exclusive to file assets (`type_id: 1`). |

### Results

Expand Down
2 changes: 1 addition & 1 deletion resources/views/entities/pages/files/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
css="col-span-2"
:required="true"
:label="__('entities/files.fields.file')">
<input type="file" multiple accept="image/*, .pdf, .gif, .webp, .pdf, .xls, .xlsx, .csv, .mp3, .ogg, .json" name="file[]" class="image w-full" id="file_{{ rand() }}" accept="" />
<input type="file" multiple accept="image/*, .pdf, .gif, .webp, .pdf, .xls, .xlsx, .csv, .mp3, .ogg, .json" name="files[]" class="image w-full" id="file_{{ rand() }}" accept="" />
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved

<p class="text-neutral-content m-0">
{{ __('crud.files.hints.limitations', ['formats' => 'jpg, jpeg, png, gif, webp, pdf, xls(x), csv, mp3, ogg, json', 'size' => Limit::readable()->upload()]) }}
Expand Down
Loading