• PHP reference
  • Models

File

class File extends AttributedModel

File model.

Properties

integer $id

ModelRelations $relations

string $type

string $token

string $name

string $mime_type

string $hash

int $size

Methods

static File|null getByToken(string $token)

Get file by token.

Parameters

  • string $token

Return Value

string url()

Get the file's publicly accessible URL.

Return Value

  • string

string thumbnail(integer $width = 320, boolean $crop = true)

Get thumbnail image URL.

Parameters

  • integer $width Desired width of thumbnail, default = 320
  • boolean $crop Whether to crop the thumbnail to be square, default true

Return Value

  • string

Inherited from Fillable

static boolean|Fillable create($fields)

Insert a new entry into the model's database table.

Parameters

  • $fields

Return Value

Inherited from Model

__construct(mixed $source = null, boolean $disable_global = false)

Model constructor. Pass in an ID (numeric) or object to start the model.

Parameters

  • mixed $source
  • boolean $disable_global

static Model[] getAll(integer $limit = null)

Get array of all table rows as model instances.

Parameters

  • integer $limit Maximum number of entries to retrieve

Return Value

static integer getCount(array|string $where = null)

Get the number of items in the model that match the query.

Parameters

  • array|string $where Array or SQL query component to build a WHERE ... query.

Return Value

  • integer

static Model|null find(integer $id)

Get the item of this model with the given ID if it exists. Returns null otherwise.

Parameters

  • integer $id

Return Value

static Model|null findWith(string|array $field, mixed $value = null)

Check if an item with a given field value (exact match) exists.

Parameters

  • string|array $field
  • mixed $value

Return Value

static Model|null getBy(string|array $field, mixed $value = null)

Get item by a specific field (exact match). Returns null on failure.

Parameters

  • string|array $field
  • mixed $value

Return Value

static Model[] getManyBy(string|array $field, mixed $value = null)

Get array of items that have a specific field value (exact match).

Parameters

  • string|array $field
  • mixed $value

Return Value

static boolean exists(integer $id)

Check if an item with a given ID exists.

Parameters

  • integer $id

Return Value

  • boolean

static boolean existsWith(string $field, mixed $value = null)

Check if an item with a given field value (exact match) exists.

Parameters

  • string $field
  • mixed $value

Return Value

  • boolean

boolean update(string|array $field, mixed $value = null)

Update a field of this entry.

Parameters

  • string|array $field
  • mixed $value

Return Value

  • boolean

boolean del()

Delete the resource from the database.

Return Value

  • boolean

object barebones()

Get a bare bones version of the Model (without db, relations, etc.).

Return Value

  • object

Inherited from AttributedModel

mixed attr(string $key, null $value = null)

Get or set a value on the model object.

Parameters

  • string $key
  • null $value

Return Value

  • mixed

mixed val(string $key, null $value = null)

Get or set a value on the model object. Alias for attr().

Parameters

  • string $key
  • null $value

Return Value

  • mixed

array attributes()

Get all metadata values for a model object.

Return Value

  • array

array vals()

Get all metadata values for a model object. Alias for attributes().

Return Value

  • array

static mixed|null getAttribute(string $type, integer $modelId, string $attributeKey, null $scope = null, boolean $cache = true)

Static function to get a parameter without having to retrieve the base model.

Parameters

  • string $type
  • integer $modelId
  • string $attributeKey
  • null $scope
  • boolean $cache

Return Value

  • mixed|null

boolean is(string $key)

Convenience method for testing if a model value is truthy (bool true, string 'true', int 1, string '1').

Parameters

  • string $key

Return Value

  • boolean