Media
class Media extends Model
Traits
Sortable model trait
Extendable Trait Allows for "Private traits"
Adds event related features to any class.
Constants
SORT_ORDER |
|
Properties
protected array | $extensionData | from ExtendableTrait | |
static protected array | $extendableCallbacks | from ExtendableTrait | |
static protected array | $extendableStaticMethods | from ExtendableTrait | |
static protected bool | $extendableGuardProperties | from ExtendableTrait | |
static protected ClassLoader | $extendableClassLoader | from ExtendableTrait | |
protected array | $emitterSingleEvents | from EventEmitter | |
protected array | $emitterEvents | from EventEmitter | |
protected array | $emitterEventSorted | from EventEmitter | |
$relation | The loaded relationships for the model. |
from HasRelationships | |
static protected array | $relationTypes | from HasRelationships | |
array | $implement | from Model | |
protected array | $attributes | from Model | |
$timestamps | |||
protected string | $timeFormat | The storage format of the model's time columns. |
from Model |
protected array | $casts | The attributes that should be casted to native types. |
|
static protected array | $eventsBooted | from Model | |
static protected string[] | $primitiveCastTypes | The built-in, primitive cast types supported by Eloquent. |
from Model |
protected | $table | ||
protected | $guarded | ||
static array | $imageExtensions | ||
$hidden | |||
protected array | $appends | ||
protected array | $autoMimeTypes | ||
$fileToAdd |
Methods
Helper method for ::extend() static method
Clear the list of extended classes so they will be re-extended.
Normalizes the provided extension name allowing for the ClassLoader to inject aliased classes
Dynamically extend a class with a specified behavior
Extracts the available methods from a behavior and adds it to the list of callable methods.
Programmatically adds a method to the extendable class
Programatically adds a property to the extendable class
Check if extendable class is extended with a behavior object
Returns a behavior object from an extendable class, example:
Short hand for getClassExtension() method, except takes the short extension name, example:
Checks if a method exists, extension equivalent of method_exists()
Get a list of class methods, extension equivalent of get_class_methods()
Checks if a property exists, extension equivalent of property_exists()
Checks if a property is accessible, property equivalent of is_callabe()
Magic method for __call()
Magic method for __callStatic()
Create a new event binding.
Create a new event binding that fires once only
Sort the listeners for a given event by priority.
Fire an event and call the listeners.
Fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.
Set a given attribute on the model.
Determine whether a value is Time castable for inbound manipulation.
Set the time format used by the model.
Returns relationship details from a supplied name.
Returns relationship details for all relations defined on this model.
Returns a relationship type based on a supplied name.
Sets a relation value directly from its attribute.
Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.
Returns default relation arguments for a given type.
Validate relation supplied arguments.
Define a one-to-one relationship.
Define a has-one-through relationship.
Define a one-to-many relationship.
Define a has-many-through relationship.
No description
No description
Define a polymorphic one-to-one relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic one-to-many relationship.
Define a polymorphic many-to-many relationship.
Define a polymorphic, inverse many-to-many relationship.
Create a new model and return the instance.
Save a new model and return the instance.
Bind some nicer events to this model, in the format of method overrides.
Remove all of the event listeners for the model Also flush registry of models that had events booted Allows painless unit testing.
Create a new model instance that is existing.
Handle the "saving" model event
Create a new Eloquent query builder for the model.
Create a generic pivot model instance.
Create a pivot model instance specific to a relation.
Save the model to the database.
Save the model and all of its relationships.
Pushes the first level of relations even if the parent model has no changes.
Locates relations with delete flag and cascades the delete event.
Sets the sort order of records to the specified orders. If the orders is undefined, the record identifier is used.
Set the polymorphic relation.
Creates a file object from a file an uploaded file.
Creates a file object from a file on the disk.
Creates a file object from raw data.
Creates a file object from url
Helper attribute for getPath.
Determine the type of a file.
No description
Helper attribute for get image width.
Helper attribute for get image height.
No description
Returns the file name without path
Returns the file extension.
Returns the last modification date as a UNIX timestamp.
Returns the public address to access the file.
Returns a local path to this file. If the file is stored remotely, it will be downloaded to a temporary directory.
Returns the path to the file, relative to the storage disk.
Determines if the file is flagged "public" or not.
Returns the file size as string.
No description
No description
Generates a unique name from the supplied file name.
No description
No description
Delete all thumbnails for this file.
Delete file contents from storage device.
Checks if directory is empty then deletes it, three levels up to match the partition directory.
Returns true if a directory contains no files.
Check file exists on storage device.
Checks if the file extension is an image and returns true or false.
Generates and returns a thumbnail url.
No description
No description
Get image dimensions
Generates a thumbnail filename.
Returns the default thumbnail options.
Generate the thumbnail
No description
No description
Get if the value of custom property with the given name.
No description
No description
Define the internal storage path, override this method to define.
Define the public address for the storage path.
Define the internal working path, override this method to define.
Define the internal storage folder, override this method to define.
Generates a partition for the file.
No description
No description
Details
in
ExtendableTrait at line 55
extendableConstruct()
Constructor.
in
ExtendableTrait at line 103
static void
extendableExtendCallback(callable $callback)
Helper method for ::extend() static method
in
ExtendableTrait at line 120
static void
clearExtendedClasses()
Clear the list of extended classes so they will be re-extended.
in
ExtendableTrait at line 131
protected string
extensionNormalizeClassName(string $name)
Normalizes the provided extension name allowing for the ClassLoader to inject aliased classes
in
ExtendableTrait at line 149
void|ExtendableTrait
extendClassWith(string $extensionName)
Dynamically extend a class with a specified behavior
in
ExtendableTrait at line 178
protected void
extensionExtractMethods(string $extensionName, object $extensionObject)
Extracts the available methods from a behavior and adds it to the list of callable methods.
in
ExtendableTrait at line 206
addDynamicMethod(string $dynamicName, callable $method, string $extension = null)
Programmatically adds a method to the extendable class
in
ExtendableTrait at line 225
addDynamicProperty(string $dynamicName, string $value = null)
Programatically adds a property to the extendable class
in
ExtendableTrait at line 249
bool
isClassExtendedWith(string $name)
Check if extendable class is extended with a behavior object
in
ExtendableTrait at line 265
mixed
getClassExtension(string $name)
Returns a behavior object from an extendable class, example:
$this->getClassExtension('Admin.Actions.FormController')
in
ExtendableTrait at line 280
mixed
asExtension(string $shortName)
Short hand for getClassExtension() method, except takes the short extension name, example:
$this->asExtension('FormController')
in
ExtendableTrait at line 301
bool
methodExists(string $name)
Checks if a method exists, extension equivalent of method_exists()
in
ExtendableTrait at line 313
array
getClassMethods()
Get a list of class methods, extension equivalent of get_class_methods()
in
ExtendableTrait at line 326
array
getDynamicProperties()
Returns all dynamic properties and their values
in
ExtendableTrait at line 344
bool
propertyExists(string $name)
Checks if a property exists, extension equivalent of property_exists()
in
ExtendableTrait at line 370
protected bool
extendableIsAccessible(mixed $class, string $propertyName)
Checks if a property is accessible, property equivalent of is_callabe()
in
ExtendableTrait at line 385
string
extendableGet(string $name)
Magic method for __get()
in
ExtendableTrait at line 410
string
extendableSet(string $name, string $value)
Magic method for __set()
in
ExtendableTrait at line 444
mixed
extendableCall(string $name, array $params = null)
Magic method for __call()
in
ExtendableTrait at line 483
static mixed
extendableCallStatic(string $name, array $params = null)
Magic method for __callStatic()
in
ExtendableTrait at line 552
protected ClassLoader|null
extensionGetClassLoader()
Gets the class loader
in
EventEmitter at line 36
EventEmitter
bindEvent(string $event, callable $callback, int $priority = 0)
Create a new event binding.
in
EventEmitter at line 52
EventEmitter
bindEventOnce(string $event, callable $callback)
Create a new event binding that fires once only
in
EventEmitter at line 66
protected void
emitterEventSortEvents(string $eventName)
Sort the listeners for a given event by priority.
in
EventEmitter at line 84
EventEmitter
unbindEvent(string $event = null)
Destroys an event binding.
in
EventEmitter at line 124
string|array
fireEvent(string $event, array $params = [], bool $halt = false)
Fire an event and call the listeners.
in
EventEmitter at line 178
mixed
fireSystemEvent(string $event, array $params = [], bool $halt = true)
Fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.
For example:
$this->fireSystemEvent('admin.form.myEvent', ['my value']);
Is equivalent to:
$this->fireEvent('form.myEvent', ['myvalue'], true);
Event::fire('admin.form.myEvent', [$this, 'myvalue'], true);
in
HasAttributes at line 19
void
addCasts(array $attributes)
Add attribute casts for the model.
in
HasAttributes at line 24
getAttribute($key)
No description
in
HasAttributes at line 46
getAttributeValue($key)
No description
in
HasAttributes at line 65
attributesToArray()
No description
in
HasAttributes at line 111
HasAttributes
setAttribute(string $key, mixed $value)
Set a given attribute on the model.
in
HasAttributes at line 170
protected
asSerialized($value)
No description
in
HasAttributes at line 175
fromSerialized($value)
No description
in
HasAttributes at line 180
protected
isSerializedCastable($key)
No description
in
HasAttributes at line 185
protected
asDateTime($value)
No description
in
HasAttributes at line 197
protected
asTime($value)
No description
in
HasAttributes at line 242
string
fromTime(Carbon|int $value)
Convert a Carbon Time to a storable string.
in
HasAttributes at line 259
protected bool
isTimeCastable(string $key)
Determine whether a value is Time castable for inbound manipulation.
in
HasAttributes at line 268
protected string
getTimeFormat()
Get the format for database stored times.
in
HasAttributes at line 280
HasAttributes
setTimeFormat(string $format)
Set the time format used by the model.
in
HasRelationships at line 58
hasRelation($name)
No description
in
HasRelationships at line 70
array
getRelationDefinition(string $name)
Returns relationship details from a supplied name.
in
HasRelationships at line 81
array
getRelationDefinitions()
Returns relationship details for all relations defined on this model.
in
HasRelationships at line 108
string
getRelationType(string $name)
Returns a relationship type based on a supplied name.
in
HasRelationships at line 124
mixed
getRelationValue(string $key)
Get a relationship.
in
HasRelationships at line 141
protected $this
setRelationValue($relationName, $value)
Sets a relation value directly from its attribute.
in
HasRelationships at line 155
string
makeRelation(string $name)
Returns a relation class object
in
HasRelationships at line 177
bool
isRelationPushable(string $name)
Determines whether the specified relation should be saved when push() is called instead of save() on the model. Default: true.
in
HasRelationships at line 194
protected array
getRelationDefaults(string $type)
Returns default relation arguments for a given type.
in
HasRelationships at line 206
handleRelation($relationName)
No description
in
HasRelationships at line 334
protected array
validateRelationArgs($relationName, $optional, array $required = [])
Validate relation supplied arguments.
in
HasRelationships at line 374
HasOne
hasOne(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)
Define a one-to-one relationship.
in
HasRelationships at line 398
HasOneThrough
hasOneThrough($related, $through, $primaryKey = null, $throughKey = null, $localKey = null, $secondLocalKey = null, $relationName = null)
Define a has-one-through relationship.
This code is a duplicate of Eloquent but uses a Rain relation class.
in
HasRelationships at line 428
HasMany
hasMany(string $related, string|null $foreignKey = null, string|null $localKey = null, null $relationName = null)
Define a one-to-many relationship.
in
HasRelationships at line 459
HasManyThrough
hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null, string|null $secondLocalKey = null, null $relationName = null)
Define a has-many-through relationship.
in
HasRelationships at line 487
belongsTo($related, $foreignKey = null, $ownerKey = null, $relationName = null)
No description
in
HasRelationships at line 508
belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relationName = null)
No description
in
HasRelationships at line 541
MorphOne
morphOne(string $related, string $name, string|null $type = null, string|null $id = null, string|null $localKey = null, null $relationName = null)
Define a polymorphic one-to-one relationship.
in
HasRelationships at line 572
protected MorphTo
morphEagerTo(string $name, string $type, string $id, $ownerKey)
Define a polymorphic, inverse one-to-one or many relationship.
in
HasRelationships at line 594
protected MorphTo
morphInstanceTo(string $target, string $name, string $type, string $id, $ownerKey)
Define a polymorphic, inverse one-to-one or many relationship.
in
HasRelationships at line 621
MorphMany
morphMany(string $related, string $name, string|null $type = null, string|null $id = null, string|null $localKey = null, null $relationName = null)
Define a polymorphic one-to-many relationship.
in
HasRelationships at line 657
MorphToMany
morphToMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, bool $inverse = false, null $relationName = null)
Define a polymorphic many-to-many relationship.
in
HasRelationships at line 705
MorphToMany
morphedByMany(string $related, string $name, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $relatedKey = null, null $relationName = null)
Define a polymorphic, inverse many-to-many relationship.
in
Model at line 88
__construct(array $attributes = [])
No description
in
Model at line 103
static Model|Model
make(array $attributes = [])
Create a new model and return the instance.
in
Model at line 117
static Model|Model
create(array $attributes = [], string $sessionKey = null)
Save a new model and return the instance.
in
Model at line 148
void
reloadRelations(string $relationName = null)
Reloads the model relationship cache.
in
Model at line 163
static
extend(Closure $callback)
Extend this object properties upon construction.
in
Model at line 171
protected
bootNicerEvents()
Bind some nicer events to this model, in the format of method overrides.
in
Model at line 214
static void
flushEventListeners()
Remove all of the event listeners for the model Also flush registry of models that had events booted Allows painless unit testing.
in
Model at line 229
Model|Model
newFromBuilder(array $attributes = [], null $connection = null)
Create a new model instance that is existing.
in
Model at line 248
protected
beforeCreate()
Handle the "creating" model event
in
Model at line 255
protected
afterCreate()
Handle the "created" model event
in
Model at line 262
protected
beforeUpdate()
Handle the "updating" model event
in
Model at line 269
protected
afterUpdate()
Handle the "updated" model event
at line 160
protected
beforeSave()
Handle the "saving" model event
in
Model at line 283
protected
afterSave()
Handle the "saved" model event
in
Model at line 290
protected
beforeDelete()
Handle the "deleting" model event
at line 178
protected
afterDelete()
After model is deleted
- clean up it's thumbnails
in
Model at line 304
protected
beforeFetch()
Handle the "fetching" model event
in
Model at line 311
protected
afterFetch()
Handle the "fetched" model event
in
Model at line 322
static void
fetching(Closure|string $callback)
Create a new native event for handling beforeFetch().
in
Model at line 334
static void
fetched(Closure|string $callback)
Create a new native event for handling afterFetch().
in
Model at line 339
setUpdatedAt($value)
No description
in
Model at line 347
setCreatedAt($value)
No description
in
Model at line 363
array
getObservableEvents()
Get the observable event names.
in
Model at line 375
protected
isRelationPurgeable($name)
No description
in
Model at line 391
Builder
newEloquentBuilder(Builder $query)
Create a new Eloquent query builder for the model.
in
Model at line 400
string
getForeignKey()
Get the default foreign key name for the model.
in
Model at line 409
__get($key)
No description
in
Model at line 414
__set($name, $value)
No description
in
Model at line 427
mixed
__call(string $method, $params)
Handle dynamic method calls into the model.
in
Model at line 448
Pivot
newPivot(Model $parent, array $attributes, string $table, bool $exists, string|null $using = null)
Create a generic pivot model instance.
in
Model at line 464
Pivot
newRelationPivot(string $relationName, Model $parent, array $attributes, string $table, bool $exists)
Create a pivot model instance specific to a relation.
in
Model at line 487
protected bool
saveInternal(array $options = [])
Save the model to the database. Is used by save()
in
Model at line 521
bool
save(array $options = null, null $sessionKey = null)
Save the model to the database.
in
Model at line 535
bool
push(array $options = null, null $sessionKey = null)
Save the model and all of its relationships.
in
Model at line 577
bool
alwaysPush(array $options = null, string $sessionKey = null)
Pushes the first level of relations even if the parent model has no changes.
in
Model at line 586
protected void
performDeleteOnModel()
Perform the actual delete query on this model instance.
in
Model at line 596
protected void
performDeleteOnRelations()
Locates relations with delete flag and cascades the delete event.
in
Sortable at line 36
static void
bootSortable()
Boot the sortable trait for this model.
in
Sortable at line 48
scopeSorted($query)
No description
in
Sortable at line 62
setSortableOrder($itemIds, null $itemOrders = null)
Sets the sort order of records to the specified orders. If the orders is undefined, the record identifier is used.
in
Sortable at line 85
string
getSortOrderColumn()
Get the name of the "sort order" column.
in
Sortable at line 90
sortWhenCreating()
No description
at line 73
mixed
attachment()
Set the polymorphic relation.
at line 84
Media
addFromRequest(UploadedFile $uploadedFile, null $tag = null)
Creates a file object from a file an uploaded file.
at line 100
Media|void
addFromFile($filePath, null $tag = null)
Creates a file object from a file on the disk.
at line 122
$this|void
addFromRaw($rawData, $filename, null $tag = null)
Creates a file object from raw data.
at line 144
$this
addFromUrl($url, $filename = null, null $tag = null)
Creates a file object from url
at line 197
string
getPathAttribute()
Helper attribute for getPath.
at line 207
string
getTypeAttribute()
Determine the type of a file.
at line 212
getExtensionAttribute()
No description
at line 221
string
getWidthAttribute()
Helper attribute for get image width.
at line 234
string
getHeightAttribute()
Helper attribute for get image height.
at line 243
getHumanReadableSizeAttribute()
No description
at line 255
getFilename()
Returns the file name without path
at line 263
getExtension()
Returns the file extension.
at line 272
int
getLastModified($fileName = null)
Returns the last modification date as a UNIX timestamp.
at line 283
getPath()
Returns the public address to access the file.
at line 292
getFullDiskPath()
Returns a local path to this file. If the file is stored remotely, it will be downloaded to a temporary directory.
at line 301
string
getDiskPath()
Returns the path to the file, relative to the storage disk.
at line 309
isPublic()
Determines if the file is flagged "public" or not.
at line 321
string
sizeToString()
Returns the file size as string.
at line 326
getMimeType()
No description
at line 337
getTypeFromExtension()
No description
at line 348
getUniqueName()
Generates a unique name from the supplied file name.
at line 360
getDiskName()
No description
at line 372
getDiskDriverName()
No description
at line 384
deleteThumbs()
Delete all thumbnails for this file.
at line 402
protected void
deleteFile(null $fileName = null)
Delete file contents from storage device.
at line 424
protected void
deleteEmptyDirectory(string $directory = null)
Checks if directory is empty then deletes it, three levels up to match the partition directory.
at line 449
protected bool|null
isDirectoryEmpty($directory)
Returns true if a directory contains no files.
at line 461
protected bool
hasFile(string $fileName = null)
Check file exists on storage device.
at line 475
isImage()
Checks if the file extension is an image and returns true or false.
at line 487
string
getThumb(array $options = [])
Generates and returns a thumbnail url.
at line 501
outputThumb($options = [])
No description
at line 505
getDefaultThumbPath($thumbPath, $default = null)
No description
at line 519
protected array|bool
getImageDimensions()
Get image dimensions
at line 531
protected string
getThumbFilename(array $options)
Generates a thumbnail filename.
at line 545
protected array
getDefaultThumbOptions(array $override = [])
Returns the default thumbnail options.
at line 572
protected
makeThumb($thumbFile, array $options)
Generate the thumbnail
at line 594
getCustomProperties()
No description
at line 602
hasCustomProperty($propertyName)
No description
at line 615
mixed
getCustomProperty(string $propertyName, mixed $default = null)
Get if the value of custom property with the given name.
at line 626
$this
setCustomProperty(string $name, mixed $value)
No description
at line 642
$this
forgetCustomProperty(string $name)
No description
at line 660
getStoragePath()
Define the internal storage path, override this method to define.
at line 668
getPublicPath()
Define the public address for the storage path.
at line 681
getTempPath()
Define the internal working path, override this method to define.
at line 694
getStorageDirectory()
Define the internal storage folder, override this method to define.
at line 705
mixed
getPartitionDirectory()
Generates a partition for the file.
at line 714
protected FilesystemAdapter
getStorageDisk()
No description
at line 719
protected
getMediaAdder()
No description