abstract class Model (View source)

Provides the model contract for the database subsystem.

Properties

protected string $table
protected string $primaryKey
protected bool $useTimestamps
protected bool $useUserTracking
protected int|string|null $actorId
protected string $createdAt
protected string $updatedAt
protected string $createdBy
protected string $updatedBy
protected bool $useSoftDeletes
protected string $deletedAt
protected list<string> $allowedFields
protected bool $allowCallbacks
protected list<string> $beforeInsert
protected list<string> $afterInsert
protected list<string> $beforeUpdate
protected list<string> $afterUpdate
protected list<string> $beforeInsertBatch
protected list<string> $afterInsertBatch
protected list<string> $beforeUpdateBatch
protected list<string> $afterUpdateBatch
protected list<string> $beforeFind
protected list<string> $afterFind
protected list<string> $beforeDelete
protected list<string> $afterDelete

Methods

Initializes this Model with the collaborators and state required by its database contract.

array
all()
array
array|null
find(int|string $id)
array|null
array|null
first(array $where = [])
array|null
array
where(array $where, int|null $limit = null)
array
bool
exists(array $where)
bool
int

Provides this part of the database contract while preserving the object's current state and driver semantics.

int
int
countWhere(array $where)
int
int|string|bool|null
save(array $data)
int|string|bool|null
array
firstOrCreate(array $attributes, array $values = [])
array
array
updateOrCreate(array $attributes, array $values = [])
array
int|string|bool|null
upsert(array $data, string|null $uniqueBy = null)
int|string|bool|null
bool
batchUpsert(array $rows, string|null $uniqueBy = null)
bool
int|string|null
insert(array $data)
int|string|null
bool
update(int|string $id, array $data)
bool
bool
insertBatch(array $rows)
bool
bool
updateBatch(array $rows, string|null $index = null)
bool
bool
delete(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

bool
bool
forceDelete(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

bool
bool
deleteWhere(array $where)
bool
array
findMany(array $ids)
array
bool
increment(int|string $id, string $column, int|float $amount = 1)

Provides this part of the database contract while preserving the object's current state and driver semantics.

bool
bool
decrement(int|string $id, string $column, int|float $amount = 1)

Provides this part of the database contract while preserving the object's current state and driver semantics.

bool
bool
restore(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

bool
bool
restoreWhere(array $where)
bool
withDeleted(bool $state = true)

Updates the query or object state used by subsequent database operations.

onlyDeleted(bool $state = true)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Provides this part of the database contract while preserving the object's current state and driver semantics.

query()

Runs the requested database operation and returns its driver-level outcome.

scoped(string $scope, mixed ...$args)

Provides this part of the database contract while preserving the object's current state and driver semantics.

applyScope(QueryBuilder $builder, string $scope, mixed ...$args)

Updates the query or object state used by subsequent database operations.

void
chunk(int $size, callable $callback)
void
string

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
string

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
string
columnName(string $column)

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
array
prepareInsertData(array $data)
array
array
prepareUpdateData(array $data)
array
array
filterAllowedFields(array $data)
array
string
now()

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
setActorId(int|string|null $id)

Updates the query or object state used by subsequent database operations.

int|string|null

Resolves the effective value from the configured database dependencies and input.

int|string|null
array

Updates the query or object state used by subsequent database operations.

void

Provides this part of the database contract while preserving the object's current state and driver semantics.

void
string
scopeMethodName(string $scope)

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
array
trigger(string $event, array $payload)
array

Details

__construct

Initializes this Model with the collaborators and state required by its database contract.

Parameters

DatabaseDriverInterface $db

all

array all()

No description

Return Value

array

find

array|null find(int|string $id)

No description

Parameters

int|string $id

Return Value

array|null

first

array|null first(array $where = [])

No description

Parameters

array $where

Return Value

array|null

where

array where(array $where, int|null $limit = null)

No description

Parameters

array $where
int|null $limit

Return Value

array

exists

bool exists(array $where)

No description

Parameters

array $where

Return Value

bool

countAll

int countAll()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

int

countWhere

int countWhere(array $where)

No description

Parameters

array $where

Return Value

int

save

int|string|bool|null save(array $data)

No description

Parameters

array $data

Return Value

int|string|bool|null

firstOrCreate

array firstOrCreate(array $attributes, array $values = [])

No description

Parameters

array $attributes
array $values

Return Value

array

updateOrCreate

array updateOrCreate(array $attributes, array $values = [])

No description

Parameters

array $attributes
array $values

Return Value

array

upsert

int|string|bool|null upsert(array $data, string|null $uniqueBy = null)

No description

Parameters

array $data
string|null $uniqueBy

Return Value

int|string|bool|null

batchUpsert

bool batchUpsert(array $rows, string|null $uniqueBy = null)

No description

Parameters

array $rows
string|null $uniqueBy

Return Value

bool

insert

int|string|null insert(array $data)

No description

Parameters

array $data

Return Value

int|string|null

update

bool update(int|string $id, array $data)

No description

Parameters

int|string $id
array $data

Return Value

bool

insertBatch

bool insertBatch(array $rows)

No description

Parameters

array $rows

Return Value

bool

updateBatch

bool updateBatch(array $rows, string|null $index = null)

No description

Parameters

array $rows
string|null $index

Return Value

bool

delete

bool delete(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

int|string $id

Return Value

bool

forceDelete

bool forceDelete(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

int|string $id

Return Value

bool

deleteWhere

bool deleteWhere(array $where)

No description

Parameters

array $where

Return Value

bool

findMany

array findMany(array $ids)

No description

Parameters

array $ids

Return Value

array

increment

bool increment(int|string $id, string $column, int|float $amount = 1)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

int|string $id
string $column
int|float $amount

Return Value

bool

decrement

bool decrement(int|string $id, string $column, int|float $amount = 1)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

int|string $id
string $column
int|float $amount

Return Value

bool

restore

bool restore(int|string $id)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

int|string $id

Return Value

bool

restoreWhere

bool restoreWhere(array $where)

No description

Parameters

array $where

Return Value

bool

withDeleted

Model withDeleted(bool $state = true)

Updates the query or object state used by subsequent database operations.

Parameters

bool $state

Return Value

Model

onlyDeleted

Model onlyDeleted(bool $state = true)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

bool $state

Return Value

Model

builder

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

QueryBuilder

query

Runs the requested database operation and returns its driver-level outcome.

Return Value

QueryBuilder

scoped

QueryBuilder scoped(string $scope, mixed ...$args)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

string $scope
mixed ...$args

Return Value

QueryBuilder

applyScope

QueryBuilder applyScope(QueryBuilder $builder, string $scope, mixed ...$args)

Updates the query or object state used by subsequent database operations.

Parameters

QueryBuilder $builder
string $scope
mixed ...$args

Return Value

QueryBuilder

cursor

No description

Return Value

Generator

chunk

void chunk(int $size, callable $callback)

No description

Parameters

int $size
callable $callback

Return Value

void

tableName

protected string tableName()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

string

requireTableName

protected string requireTableName()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

string

columnName

protected string columnName(string $column)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

string $column

Return Value

string

prepareInsertData

protected array prepareInsertData(array $data)

No description

Parameters

array $data

Return Value

array

prepareUpdateData

protected array prepareUpdateData(array $data)

No description

Parameters

array $data

Return Value

array

filterAllowedFields

protected array filterAllowedFields(array $data)

No description

Parameters

array $data

Return Value

array

now

protected string now()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

string

setActorId

Model setActorId(int|string|null $id)

Updates the query or object state used by subsequent database operations.

Parameters

int|string|null $id

Return Value

Model

resolveActorId

protected int|string|null resolveActorId()

Resolves the effective value from the configured database dependencies and input.

Return Value

int|string|null

prepareDeleteData

protected array prepareDeleteData()

No description

Return Value

array

applySoftDeleteScope

protected QueryBuilder applySoftDeleteScope(QueryBuilder $builder)

Updates the query or object state used by subsequent database operations.

Parameters

QueryBuilder $builder

Return Value

QueryBuilder

resetSoftDeleteScope

protected void resetSoftDeleteScope()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

void

scopeMethodName

protected string scopeMethodName(string $scope)

Provides this part of the database contract while preserving the object's current state and driver semantics.

Parameters

string $scope

Return Value

string

trigger

protected array trigger(string $event, array $payload)

No description

Parameters

string $event
array $payload

Return Value

array