class Model implements ExtenderInterface

Methods

__construct(string $modelClass)

No description

cast(string $attribute, string $cast)

Add a custom attribute type cast. Should not be applied to non-extension attributes.

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 `::class` attribute of an invokable class.

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

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

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

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

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

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

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

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

relationship(string $name, callable|string $callback)

Add a relationship from this model to another model.

void
extend( Container $container, Extension|null $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 cast(string $attribute, string $cast)

Add a custom attribute type cast. Should not be applied to non-extension attributes.

Parameters

string $attribute : The new attribute name.
string $cast : The cast type. See https://laravel.com/docs/13.x/eloquent-mutators#attribute-casting

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 `::class` attribute of an invokable class.

Parameters

string $attribute
mixed $value

Return Value

Model

Model belongsTo(string $name, string $related, string|null $foreignKey = null, string|null $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 : The name of the relation. This doesn't have to be anything in particular, but has to be unique from other relation names for this model, and should work as the name of a method.
string $related : The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel.
string|null $foreignKey : The foreign key attribute of the parent model.
string|null $ownerKey : The primary key attribute of the parent model.

Return Value

Model

Model belongsToMany(string $name, string $related, string|null $table = null, string|null $foreignPivotKey = null, string|null $relatedPivotKey = null, string|null $parentKey = null, string|null $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 : The name of the relation. This doesn't have to be anything in particular, but has to be unique from other relation names for this model, and should work as the name of a method.
string $related : The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel.
string|null $table : The intermediate table for this relation
string|null $foreignPivotKey : The foreign key attribute of the parent model.
string|null $relatedPivotKey : The associated key attribute of the relation.
string|null $parentKey : The key name of the parent model.
string|null $relatedKey : The key name of the related model.

Return Value

Model

Model hasOne(string $name, string $related, string|null $foreignKey = null, string|null $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 : The name of the relation. This doesn't have to be anything in particular, but has to be unique from other relation names for this model, and should work as the name of a method.
string $related : The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel.
string|null $foreignKey : The foreign key attribute of the parent model.
string|null $localKey : The primary key attribute of the parent model.

Return Value

Model

Model hasMany(string $name, string $related, string|null $foreignKey = null, string|null $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 : The name of the relation. This doesn't have to be anything in particular, but has to be unique from other relation names for this model, and should work as the name of a method.
string $related : The ::class attribute of the model, which should extend \Flarum\Database\AbstractModel.
string|null $foreignKey : The foreign key attribute of the parent model.
string|null $localKey : The primary key attribute of the parent model.

Return Value

Model

Model relationship(string $name, callable|string $callback)

Add a relationship from this model to another model.

Parameters

string $name : The name of the relation. This doesn't have to be anything in particular, but has to be unique from other relation names for this model, and should work as the name of a method.
callable|string $callback The callable can be a closure or invokable class, and should accept: - $instance: An instance of this model. The callable should return: - $relationship: A Laravel Relationship object. See relevant methods of models like \Flarum\User\User for examples of how relationships should be returned.

Return Value

Model

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

Parameters

Container $container
Extension|null $extension

Return Value

void