abstract class Model implements ArrayAccess, JsonSerializable (View source)

Traits

Properties

protected array $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 bool $soft_delete

Enable the soft deletion

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

static protected Builder $builder

The query builder instance

Methods

string
getKey()

Retrieves the primary key

belongsTo(string $related, string|null $foreign_key = null, string|null $local_key = null)

The has one relative

belongsToMany(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The belongs to many relative

hasMany(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The has many relative

hasOne(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The has one relative

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.

static Collection
all(array $columns = [])

Get all records

static Model|null
first()

Get first rows

static Model|null
latest()

Get latest

static Model|null
find(int|string|array $id, array $select = ['*'])

find

static Collection
findBy(string $column, mixed $value)

Find by column name

static bool
describe()

Returns the description of the table

static Model
findAndDelete(int|string|array $id, array $select = ['*'])

Find information and delete it

static Model
findOrFail(int|string $id, array|callable $select = ['*'])

Find information by id or throws an exception in data box not found

static Model
create(array $data)

Create a persist information

static array
paginate(int $page_number, int $current = 0, int|null $chunk = null)

Pagination configuration

static void
deleted(callable $cb)

Allows to associate listener

static void
created(callable $cb)

Allows to associate a listener

static void
updated(callable $cb)

Allows to associate a listener

static Builder
query()

Initialize the connection

mixed
getKeyValue()

Retrieves the primary key value

int
save()

Save aliases on insert action

int
update(array $attributes)

Delete a record

int
delete()

Delete a record

static int
deleteBy(string $column, string|int $value)

Delete Active Record by column name

bool
touch()

Used to update the timestamp.

void
setAttributes(array $attributes)

Assign values to class attributes

void
setAttribute(string $key, string $value)

Assign a value

setConnection(string $connection)

Set connection point

array
getAttributes()

Retrieves the list of attributes.

mixed
getAttribute(string $key)

Allows you to recover an attribute

string
getTable()

Get the table name.

array
toArray()

Returns the data

string
toJson()

Returns the data

array
jsonSerialize()

No description

mixed
__get(string $name)

__get

__set(string $name, $value)

__set

string
__toString()

__toString

mixed
__call(string $name, array $arguments)

__call

static mixed
__callStatic(string $name, array $arguments)

__callStatic

Details

string getKey()

Retrieves the primary key

Return Value

string

BelongsTo belongsTo(string $related, string|null $foreign_key = null, string|null $local_key = null)

The has one relative

Parameters

string $related
string|null $foreign_key
string|null $local_key

Return Value

BelongsTo

BelongsToMany belongsToMany(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The belongs to many relative

Parameters

string $related
string|null $primary_key
string|null $foreign_key

Return Value

BelongsToMany

HasMany hasMany(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The has many relative

Parameters

string $related
string|null $primary_key
string|null $foreign_key

Return Value

HasMany

HasOne hasOne(string $related, string|null $primary_key = null, string|null $foreign_key = null)

The has one relative

Parameters

string $related
string|null $primary_key
string|null $foreign_key

Return Value

HasOne

void offsetSet(mixed $offset, mixed $value)

_offsetSet

Parameters

mixed $offset
mixed $value

Return Value

void

See also

http://php.net/manual/fr/class.arrayaccess.php

bool offsetExists(mixed $offset)

_offsetExists

Parameters

mixed $offset

Return Value

bool

See also

http://php.net/manual/fr/class.arrayaccess.php

void offsetUnset(mixed $offset)

_offsetUnset

Parameters

mixed $offset

Return Value

void

See also

http://php.net/manual/fr/class.arrayaccess.php

mixed offsetGet(mixed $offset)

_offsetGet

Parameters

mixed $offset

Return Value

mixed

See also

http://php.net/manual/fr/class.arrayaccess.php

array __serialize()

Serialize model

Return Value

array

void __unserialize(array $attributes)

Unserialize

Parameters

array $attributes

Return Value

void

__construct(array $attributes = [])

Model constructor.

Parameters

array $attributes

static Collection all(array $columns = [])

Get all records

Parameters

array $columns

Return Value

Collection

static Model|null first()

Get first rows

Return Value

Model|null

static Model|null latest()

Get latest

Return Value

Model|null

static Model|null find(int|string|array $id, array $select = ['*'])

find

Parameters

int|string|array $id
array $select

Return Value

Model|null

static Collection findBy(string $column, mixed $value)

Find by column name

Parameters

string $column
mixed $value

Return Value

Collection

static bool describe()

Returns the description of the table

Return Value

bool

static Model findAndDelete(int|string|array $id, array $select = ['*'])

Find information and delete it

Parameters

int|string|array $id
array $select

Return Value

Model

static Model findOrFail(int|string $id, array|callable $select = ['*'])

Find information by id or throws an exception in data box not found

Parameters

int|string $id
array|callable $select

Return Value

Model

Exceptions

NotFoundException

static Model create(array $data)

Create a persist information

Parameters

array $data

Return Value

Model

static array paginate(int $page_number, int $current = 0, int|null $chunk = null)

Pagination configuration

Parameters

int $page_number
int $current
int|null $chunk

Return Value

array

static void deleted(callable $cb)

Allows to associate listener

Parameters

callable $cb

Return Value

void

Exceptions

static void created(callable $cb)

Allows to associate a listener

Parameters

callable $cb

Return Value

void

Exceptions

static void updated(callable $cb)

Allows to associate a listener

Parameters

callable $cb

Return Value

void

Exceptions

static Builder query()

Initialize the connection

Return Value

Builder

Exceptions

mixed getKeyValue()

Retrieves the primary key value

Return Value

mixed

int save()

Save aliases on insert action

Return Value

int

Exceptions

int update(array $attributes)

Delete a record

Parameters

array $attributes

Return Value

int

Exceptions

int delete()

Delete a record

Return Value

int

Exceptions

static int deleteBy(string $column, string|int $value)

Delete Active Record by column name

Parameters

string $column
string|int $value

Return Value

int

bool touch()

Used to update the timestamp.

Return Value

bool

void setAttributes(array $attributes)

Assign values to class attributes

Parameters

array $attributes

Return Value

void

void setAttribute(string $key, string $value)

Assign a value

Parameters

string $key
string $value

Return Value

void

Builder setConnection(string $connection)

Set connection point

Parameters

string $connection

Return Value

Builder

array getAttributes()

Retrieves the list of attributes.

Return Value

array

mixed getAttribute(string $key)

Allows you to recover an attribute

Parameters

string $key

Return Value

mixed

string getTable()

Get the table name.

Return Value

string

array toArray()

Returns the data

Return Value

array

string toJson()

Returns the data

Return Value

string

array jsonSerialize()

No description

Return Value

array

mixed __get(string $name)

__get

Parameters

string $name

Return Value

mixed

__set(string $name, $value)

__set

Parameters

string $name
$value

string __toString()

__toString

Return Value

string

mixed __call(string $name, array $arguments)

__call

Parameters

string $name
array $arguments

Return Value

mixed

static mixed __callStatic(string $name, array $arguments)

__callStatic

Parameters

string $name
array $arguments

Return Value

mixed