File fields

type:file renders a file input. The uploaded file is stored in storage/crudadmin/uploads/{table}/{field} (published as public/uploads) and the column holds only the filename.
File upload field generated in the administration form
  • The filename is slugged from the original name, My Contract.PDF is stored as my-contract.pdf. When the file already exists, a number is appended (my-contract-1.pdf), files are never overwritten.
  • Uploading a new file replaces the previous one and deletes it from the storage. Removing the file in the form clears the column and deletes the file.
  • Deleting the record deletes its files.
  • The default size limit is max:10240 (kilobytes). Use extensions to restrict the file types.
  • required is checked only when no file is stored yet, so an existing record can be saved without uploading the file again.
  • Very large images are downscaled to the maximum image size (3840×2160 by default). Uploaded files are not cropped.
The model returns the file as an object with the URL, resizing and download helpers, see Images and files.

Images

image is a shortcut for type:file|image|max:5120. Non-image files are rejected and the size is limited to 5 MB. A max written on the field wins.

Multiple files

multiple stores several files in one field as a JSON array. The model returns a collection of files.
  • In the form, stored files can be reordered and removed, new files are appended. Removed files are deleted from the storage.
  • max and extensions are checked for every uploaded file.
  • required needs at least one stored or uploaded file.

One record per file

multirows lets the user upload several files in the create form and creates a separate record for each file. Other values from the form are copied into each record. When editing, the field holds a single file.

Changing the filename

Define set{Key}Filename($filename) on the model to change the name of an uploaded file. The method receives the slugged filename with its extension, the collision number is added afterwards.
app/Models/Order.php

Private files

private stores the file in storage/crudadmin/uploads_private, which is not published in the public directory. Serve the file through the signed download() link.
To make all file fields of a model private, use $privateUploads. Image compression, deleting old files and uploading from code are described in Model uploads.

Image size in API responses

resize sets the default image size in admin API responses. The file URL returned by the API points to the resized image.
resize:600,400 crops to exactly 600×400, resize:600 keeps the ratio by width, resize:null,400 by height. A multiple field returns the list of resized URLs.

Uploader

type:uploader renders an asynchronous uploader. The field has no database column. Files uploaded before the record exists are stored in {table}/{field}/temp/{uuid} and moved to {table}/{field}/{id} after the record is created.