Media
States a file sits in from picker to collection, and how it moves.
Rate limit is 10 per minute for a user who only has the MyClic participant and store employee roles, 200 for everyone else. synchronizeMedia deletes media missing from the UUID list unless preserveExisting is on.
Form media
Use MediaUploader.vue to show media and upload temporary files. The files attach to the resource when the Inertia form is saved.
Code:
resources/js/components/Backoffice/Shared/Forms/MediaUploader/MediaUploader.vueresources/js/components/Backoffice/Shared/Forms/MediaUploader/TemporaryFileUploadRules.tsresources/js/components/Backoffice/Shared/Forms/MediaUploader/UploadedFile.ts
Users can drag and drop or click to upload. Multiple items can be dragged to sort. An optional cover flag marks one item. Items can be removed from the list. Each upload is validated on the server. Inline errors show validation issues. A toast shows if the server fails. Files become temporary uploads only after they pass validation.
TemporaryFileUploadRules
The front-end rules appear in the requirements tooltip. Maximum files and accepted MIME types are also enforced in the browser, so the picker will not add a sixth file when the max is five, or a video when only images are allowed.
TemporaryFileUploadGroup
Each use of MediaUploader.vue is tied to a TemporaryFileUploadGroup enum case in Domain/Media/Enums/TemporaryFileUploadGroup.php. Add the enum case first, then the form request, then the match arm in Interfaces/App/Actions/ValidateTemporaryFileUploadGroup.php. Uploads validate Rule::enum(TemporaryFileUploadGroup::class).
Cases include category images, product images, challenge images, questionnaire cover and logo, store logo, provider logo and images, media catalog, profile picture, and the provider-backoffice and store-backoffice variants.
Uploading files
There is one upload endpoint for authenticated users, used by the backoffice and the storefront. Rate limit media.upload.temporary in app/Providers/MediaServiceProvider.php: 10 per minute for a user who only has the MyClic participant and store employee roles, 200 per minute for everyone else.
Generic validation requires group, UUID, and a file. Extra rules come from the group's form request. Uploads are stored as TemporaryUpload rows in temporary_uploads, each with one Media row in the default collection.
Code:
Interfaces/App/Controllers/Media/UploadTemporaryFile.phpInterfaces/App/Requests/Media/UploadTemporaryFileRequest.phpInterfaces/App/Actions/ValidateTemporaryFileUploadGroup.phpDomain/Media/Models/TemporaryUpload.php
TemporaryUpload stores the group and the session id (tied to the user). Media points at the file on disk until the form attaches it to the target model.
Saving the form
Each valid upload returns the Media UUID. The form keeps an array of UUIDs, for example form.images on a category. Existing media and temporary uploads are both Media records, so the form only sends UUIDs. Files are not revalidated. Interfaces/App/Rules/MediaRules.php checks that each UUID is either existing media on the expected model or a temporary upload in the expected group.
Attaching media
Callers pass ValidatedMediaItem::createFromUuids() into $model->synchronizeMedia($items, $uploadGroup)->toMediaCollection(...) on Domain/Media/Models/HandlesMedia.php. That sets sort order, deletes media missing from the list unless preserve is on, copies temporary Media onto the model, and deletes the TemporaryUpload row.
Local and test media
Rearranging seeded media right after a test deploy does not work. Delete the resource's media first, upload new files, save, go back to the index, then edit again.