Skip to content

File

Class: Code16\Sharp\Show\Fields\SharpShowFileField

The purpose of this field is to present a downloadable file to the user.

Configuration

setLabel

Set the field label.

setStorageDisk

Declare the file storage disk (as configured in Laravel's config/filesystem.php config file).

setStorageBasePath

Declare the destination base storage path.

You can use the {id} special placeholder to declare the instance id in the path, which can be useful sometimes. For instance: $field-⁠>setStorageBasePath('/users/{id}/avatar')

Transformer

Sharp expects an array with 3 keys:

php
[
    'name' => '', // Relative file path
    'thumbnail' => '', // 1000px w * 400px h thumbnail full url
    'size' => x, // Size in bytes
]
[
    'name' => '', // Relative file path
    'thumbnail' => '', // 1000px w * 400px h thumbnail full url
    'size' => x, // Size in bytes
]

I you are using Sharp solution for uploads, meaning the SharpUploadModel class detailed here, you can simply call the built-in transformer:

php
$this->setCustomTransformer("file", new SharpUploadModelFormAttributeTransformer());
$this->setCustomTransformer("file", new SharpUploadModelFormAttributeTransformer());

This transformer allows to act a bit n the thumbnail creation part, see its constructor for more details.

Released under the MIT License.