CrudAdmin stores files uploaded in the administration and gives you a file object to render them, resize images and serve downloads. File fields and their parameters are described in File uploads.

Reading a file from a model

Rendered as a string, the file returns its public URL, for example https://example.com/uploads/articles/image/my-photo.jpg.
A multiple file field returns a collection of file objects.

Resizing images

resize($width, $height) takes the width as its first argument and the height as its second. With both defined, the image is cropped to the exact size. With only one defined, the other is calculated from the ratio.
resize() returns a new file object pointing to the resized image. SVG files are returned unchanged.
The image is resized on the first request and stored in a cache for later requests.

Advanced image operations

The file object uses Intervention Image, so it can perform any operation that library supports. The image($mutators) method takes an array whose keys are the function names and whose values are the arguments of those functions.
This example crops the image with fit and then blurs it with blur.

Helper methods

delete

Removes the file from the storage and returns true, or false when the file does not exist. The column value is not changed.

download

Returns a signed URL which downloads the file. It works for private files too.

filesize

Returns the size in bytes. Pass true for a formatted size.