Model
abstract class Model implements ArrayAccess, JsonSerializable (View source)
Static method hints for calls dispatched through __callStatic() to the
underlying Builder (and its parent QueryBuilder). They let IDEs and
static analysers type-check fluent chains such as
User::where('active', true)->orderBy('id')->paginate(15).
Selection & aliasing
Traits
Properties
| static protected Builder | $builder | The query builder instance |
|
| $hidden | The hidden field |
||
| protected bool | $timestamps | Enable the timestamps support |
|
| protected string | $prefix | Define the table prefix |
|
| protected bool | $auto_increment | Enable the autoincrement support |
|
| protected string | $latest | Defines the column where the query construct will use for the last query |
|
| protected string | $created_at | Defines the created_at column name |
|
| protected string | $updated_at | Defines the created_at column name |
|
| protected array | $attributes | The table columns listing |
|
| protected array | $dates | The date mutation |
|
| protected array | $casts | The casts mutation |
|
| protected string | $primary_key | The table primary key column name |
|
| protected string | $primary_key_type | The table primary key type |
|
| protected string | $table | The table name |
|
| protected ?string | $connection | The connection name |
Methods
The has one relative
The belongs to many relative
The has many relative
The has one relative
Retrieves the primary key
Model constructor.
Get the table name.
No description
Set the connection
Set connection point
Get all records
Get first rows
retrieve by column name
retrieve information and delete it
retrieve
No description
Retrieves the primary key value
retrieve information by id or throws an exception in data box not found
persist aliases on insert action
Delete a record
Pagination configuration
Allows to associate listener
Allows to associate listener
Allows to associate a listener
Allows to associate a listener
Allows to associate a listener
Allows to associate a listener
Delete Active Record by column name
__callStatic
Retrieves the primary key
Used to update the timestamp.
Assign a value
Retrieves the list of attributes.
Assign values to class attributes
Allows you to recover an attribute
Set a loaded relationship on the model's in-memory store.
Returns the data
No description
__get
__set
__toString
Returns the data
__call
No description
No description
No description
No description
No description
Joins
No description
No description
Grouping, ordering, limiting, locking
No description
Aggregates & terminal reads
No description
No description
No description
No description
No description
?object last()
No description
No description
Write actions
No description
No description
No description
No description
Details
BelongsTo
belongsTo(string $related, string|null $foreign_key = null, string|null $primary_key = null)
The has one relative
BelongsToMany
belongsToMany(string $related, string|null $primary_key = null, string|null $foreign_key = null)
The belongs to many relative
HasMany
hasMany(string $related, string|null $foreign_key = null, string|null $primary_key = null)
The has many relative
HasOne
hasOne(string $related, string|null $foreign_key = null, string|null $primary_key = null)
The has one relative
string
getKey()
Retrieves the primary key
protected void
fireEvent(string $event)
Fire event
static protected string
formatEventName(string $event)
Get event name
void
offsetSet(mixed $offset, mixed $value)
_offsetSet
bool
offsetExists(mixed $offset)
_offsetExists
void
offsetUnset(mixed $offset)
_offsetUnset
mixed
offsetGet(mixed $offset)
_offsetGet
array
__serialize()
Serialize model
void
__unserialize(array $attributes)
Unserialize
__construct(array $attributes = [])
Model constructor.
string
getTable()
Get the table name.
string|null
getConnection()
No description
static Builder
query()
Initialize the connection
static Model
connection(string $name)
Set the connection
Builder
setConnection(string $name)
Set connection point
static Collection
all(array $columns = [])
Get all records
static Model|null
latest()
Get latest
static array|object|null
first()
Get first rows
static Collection
retrieveBy(string $column, mixed $value)
retrieve by column name
static Collection|Model|null
retrieveAndDelete(int|string|array $id, array $select = ['*'])
retrieve information and delete it
static array|object|null
retrieve(int|string|array $id, array $select = ['*'])
retrieve
static int
delete()
No description
mixed
getKeyValue()
Retrieves the primary key value
static array|object
retrieveOrFail(int|string $id, array $select = ['*'])
retrieve information by id or throws an exception in data box not found
static Model
create(array $data)
Create a persist information
int
persist()
persist aliases on insert action
int|bool
update(array $attributes)
Delete a record
static Pagination
paginate(int $page_number, int $current = 0, int|null $chunk = null)
Pagination configuration
static void
deleted(callable $cb)
Allows to associate listener
static void
deleting(callable $cb)
Allows to associate listener
static void
creating(callable $cb)
Allows to associate a listener
static void
created(callable $cb)
Allows to associate a listener
static void
updating(callable $cb)
Allows to associate a listener
static void
updated(callable $cb)
Allows to associate a listener
static int
deleteBy(string $column, mixed $value)
Delete Active Record by column name
static Builder|Collection|Model|mixed
__callStatic(string $name, array $arguments)
__callStatic
string
getKeyType()
Retrieves the primary key
bool
touch()
Used to update the timestamp.
void
setAttribute(string $key, string $value)
Assign a value
array
getAttributes()
Retrieves the list of attributes.
void
setAttributes(array $attributes)
Assign values to class attributes
mixed
getAttribute(string $key)
Allows you to recover an attribute
void
setRelation(string $name, mixed $value)
Set a loaded relationship on the model's in-memory store.
Used by eager loading to pre-populate a relation so a later access resolves from memory instead of issuing a query.
array
toArray()
Returns the data
array
jsonSerialize()
No description
mixed
__get(string $name)
__get
__set(string $name, mixed $value)
__set
string
__toString()
__toString
string
toJson()
Returns the data
mixed
__call(string $name, array $arguments = [])
__call
static Builder
as(string $as)
No description
static Builder
select(array $select = '[]')
No description
static Builder
distinct(string $column)
WHERE clauses
static Builder
where(string $column, mixed $comparator = '\'=\'', mixed $value = 'null')
No description
static Builder
whereRaw(string $where, array $data = '[]')
No description
static Builder
whereNull(string $column)
No description
static Builder
whereNotNull(string $column)
No description
static Builder
whereBetween(string $column, array $range)
No description
static Builder
whereNotBetween(string $column, array $range)
No description
static Builder
whereDifferent(string $column, mixed $value)
No description
static Builder
whereIn(string $column, array $range)
No description
static Builder
whereNotIn(string $column, array $range)
Joins
static Builder
join(string $table, string $first, mixed $comparator = '\'=\'', ?string $second = 'null')
No description
static Builder
leftJoin(string $table, string $first, mixed $comparator = '\'=\'', ?string $second = 'null')
No description
static Builder
rightJoin(string $table, string $first, mixed $comparator = '\'=\'', ?string $second = 'null')
Grouping, ordering, limiting, locking
static Builder
orderBy(string $column, string $type = '\'asc\'')
No description
static Builder
take(int $limit)
No description
static Builder
jump(int $offset = '0')
No description
static Builder
lockForUpdate()
No description
static Builder
sharedLock()
Aggregates & terminal reads
static int
count(string $column = '\'*\'')
No description
static int|float
max(string $column)
No description
static int|float
min(string $column)
No description
static int|float
avg(string $column)
No description
static int|float
sum(string $column)
No description
void
static()
?object last()
static Collection|null
get(array $columns = '[]')
No description
static bool
exists(?string $column = 'null', mixed $value = 'null')
No description
static string
toSql()
Write actions
static int
remove(string $column, mixed $comparator = '\'=\'', mixed $value = 'null')
No description
static int
increment(string $column, int $step = '1')
No description
static int
decrement(string $column, int $step = '1')
No description
static bool
truncate()
No description