FileUploadResumableField
HasFilesTrait
You should add the Yadda\Enso\Media\Traits\HasFilesTrait trait to any model that uses this field. This will allow Enso to keep track of which files are used by which model and allow us to prevent deleting files when they are in use.
use Yadda\Enso\Media\Traits\HasFilesTrait;
class Thing extends Model {
use HasFilesTrait;
}
Creating a FileUploadResumableField
When creating a field of this type, the field "name" (passed into the __construct or make methods) should be the name of the relationship that this field will save into.
Note: Previously, belongsTo relationships required you to pass in the name of the field that would store the files key, and then additionaly set the relationship name using setRelationshipName. This method will still work for the time being for backwards compatability, but is Deprecated.
Relationship Types
Currently this field Handles belongTo and belongsToMany relations. hasOne and hasMany relationships do not make sense for file uploads (based on how they are stored in the database). Other relationship are not currently implemented, but may be in the future.
Ordering Files
Should your FileUploadFieldResumable represent an orderable relationship, you should define the name of the column on the pivot table that is user to order the relationship:
$field->getRelationshipOrderBy() // returns the current column name
$field->setRelationshipOrderBy('order') // Sets the column to order relationship by to 'order'
$field->relationshipOrderBy() // returns the current column name
$field->relationshipOrderBy('order') // Sets the column to order relationship by to 'order'
Max Files
You can define the maximum number of files this field can hold at any given time. By default, this is a single file.
You can access and change this limit:
$field->getMaxFiles(); // Returns current max files
$field->setMaxFiles(5); // Sets current max files to 5
$field->maxFiles(); // Returns current max files
$field->maxFiles(12); // Sets current max files to 12
Max File Size
You can define the maximum size (in MB) of files that can be uploaded to this field. By default, this is a 2mb.
You can access and change this limit:
$field->getMaxFileSize(); // Returns current max file size
$field->setMaxFileSize(5); // Sets current max file size to 5mb
$field->maxFileSize(); // Returns current max file size
$field->maxFileSize(1); // Sets current max file size to 1mb
Upload Path
Any uploaded files will be stored to a folder inside storage/app/public/media.
By default this folder will be named general. Generally we use images for images, audio for audio, etc.
You can access and change this path:
$field->getUploadPath(); // Returns current upload path
$field->setUploadPath('images'); // Sets upload path to 'images'
$field->uploadPath(); // Returns current upload path
$field->uploadPath('images'); // Sets upload path to 'images'