class Model implements ExtenderInterface

Methods

__construct(string $modelClass)

No description

dateAttribute(string $attribute)

<p>Add an attribute to be treated as a date.</p>

default(string $attribute, mixed $value)

<p>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.</p>

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

<p>Establish a simple belongsTo relationship from this model to another model.</p>

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

<p>Establish a simple belongsToMany relationship from this model to another model.</p>

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

<p>Establish a simple hasOne relationship from this model to another model.</p>

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

<p>Establish a simple hasMany relationship from this model to another model.</p>

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

<p>Add a relationship from this model to another model.</p>

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

No description

Details

__construct(string $modelClass)

Parameters

string $modelClass

Model dateAttribute(string $attribute)

<p>Add an attribute to be treated as a date.</p>

Parameters

string $attribute

Return Value

Model

Model default(string $attribute, mixed $value)

<p>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.</p>

Parameters

string $attribute
mixed $value

Return Value

Model

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

<p>Establish a simple belongsTo relationship from this model to another model.</p>

<p>This represents an inverse one-to-one or inverse one-to-many relationship. For more complex relationships, use the -&gt;relationship method.</p>

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)

<p>Establish a simple belongsToMany relationship from this model to another model.</p>

<p>This represents a many-to-many relationship. For more complex relationships, use the -&gt;relationship method.</p>

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)

<p>Establish a simple hasOne relationship from this model to another model.</p>

<p>This represents a one-to-one relationship. For more complex relationships, use the -&gt;relationship method.</p>

Parameters

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

Return Value

Model

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

<p>Establish a simple hasMany relationship from this model to another model.</p>

<p>This represents a one-to-many relationship. For more complex relationships, use the -&gt;relationship method.</p>

Parameters

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

Return Value

Model

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

<p>Add a relationship from this model to another model.</p>

Parameters

string $name
callable|string $callback <p>The callable can be a closure or invokable class, and should accept:</p> <ul> <li>$instance: An instance of this model.</li> </ul> <p>The callable should return:</p> <ul> <li>$relationship: A Laravel Relationship object. See relevant methods of models like \Flarum\User\User for examples of how relationships should be returned.</li> </ul>

Return Value

Model

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

Parameters

Container $container
Extension $extension