class Model implements ExtenderInterface

Methods

__construct(string $modelClass)

No description

dateAttribute(string $attribute)

Add an attribute to be treated as a date.

default(string $attribute, mixed $value)

Add a default value for a given attribute, which can be an explicit value, a closure, or an instance of an invokable class. Unlike with some other extenders, it CANNOT be the <code>::class</code> attribute of an invokable class.

belongsTo(string $name, string $related, string $foreignKey = null, string $ownerKey = null)

Establish a simple belongsTo relationship from this model to another model.

belongsToMany(string $name, string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null)

Establish a simple belongsToMany relationship from this model to another model.

hasOne(string $name, string $related, string $foreignKey = null, string $localKey = null)

Establish a simple hasOne relationship from this model to another model.

hasMany(string $name, string $related, string $foreignKey = null, string $localKey = null)

Establish a simple hasMany relationship from this model to another model.

relationship(string $name, $callback)

Add a relationship from this model to another model.

extend(Container $container, Extension $extension = null)

No description

Details

__construct(string $modelClass)

Parameters

string $modelClass The ::class attribute of the model you are modifying. This model should extend from \Flarum\Database\AbstractModel.

Model dateAttribute(string $attribute)

Add an attribute to be treated as a date.

Parameters

string $attribute

Return Value

Model

Model default(string $attribute, mixed $value)

Add a default value for a given attribute, which can be an explicit value, a closure, or an instance of an invokable class. Unlike with some other extenders, it CANNOT be the <code>::class</code> attribute of an invokable class.

Parameters

string $attribute
mixed $value

Return Value

Model

Model belongsTo(string $name, string $related, string $foreignKey = null, string $ownerKey = null)

Establish a simple belongsTo relationship from this model to another model.

This represents an inverse one-to-one or inverse one-to-many relationship. For more complex relationships, use the ->relationship method.

Parameters

string $name
string $related
string $foreignKey
string $ownerKey

Return Value

Model

Model belongsToMany(string $name, string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null)

Establish a simple belongsToMany relationship from this model to another model.

This represents a many-to-many relationship. For more complex relationships, use the ->relationship method.

Parameters

string $name
string $related
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey

Return Value

Model

Model hasOne(string $name, string $related, string $foreignKey = null, string $localKey = null)

Establish a simple hasOne relationship from this model to another model.

This represents a one-to-one relationship. For more complex relationships, use the ->relationship method.

Parameters

string $name
string $related
string $foreignKey
string $localKey

Return Value

Model

Model hasMany(string $name, string $related, string $foreignKey = null, string $localKey = null)

Establish a simple hasMany relationship from this model to another model.

This represents a one-to-many relationship. For more complex relationships, use the ->relationship method.

Parameters

string $name
string $related
string $foreignKey
string $localKey

Return Value

Model

Model relationship(string $name, $callback)

Add a relationship from this model to another model.

Parameters

string $name
$callback

Return Value

Model

extend(Container $container, Extension $extension = null)

Parameters

Container $container
Extension $extension