HasConstantInstances
trait HasConstantInstances
Some models have fixed, "constant" instances. An example is the Role model, which may have e.g. the roles "admin" and "user". These are always the same and do not change.
This trait makes it possible to call these constant instances of the model as static methods. With the Role model you would be able to call Role::admin() or Role::user() to get the model instances or Role::adminId() or Role::userId() to get the IDs of the model instances.
Constant instances are defined in the INSTANCES constant array of the model. It maps keys ("admin", "user") to the "name" attributes of the models in the database which may or may not be the same than the keys. Example:
const INSTANCES = [ 'admin' => 'Admin', 'user' => 'User', ];
Methods
Get one of the instances of this model that are defined in the INSTANCES constant array.
Details
at line 37
static Model|int
__callStatic(string $key, mixed $arguments)
Get one of the instances of this model that are defined in the INSTANCES constant array.