QueryableModel
abstract class QueryableModel implements Arrayable, ArrayAccess, Jsonable, JsonSerializable, UrlRoutable
Traits
Constants
CREATED_AT |
The name of the "created at" column. |
UPDATED_AT |
The name of the "updated at" column. |
Properties
protected string | $defaultOrderByField | Determines the default field to order the query by | from Queryable |
protected string | $defaultSortDirection | Determines the default direction to order the query by | from Queryable |
protected string|null | $connection | The connection name for the model. | |
protected int | $perPage | The number of models to return for pagination. | |
protected bool | $useChunking | Determines if QueryableModel::all() calls in queries should chunk the result. | |
bool | $exists | Indicates if the model exists. | |
bool | $wasRecentlyCreated | Indicates if the model was inserted during the current request lifecycle. | |
static protected array | $traitInitializers | The array of trait initializers that will be called on each new instance. | |
static protected array | $booted | The array of booted models. | |
protected array | $attributes | The interal storage of the model data. | |
protected string | $relation | The relation associated with the model. | |
protected int | $relationId | The directory_id associated with the model. | |
protected string | $primaryField | The primary field for the model. | |
protected string | $keyType | The "type" of the primary key ID. | |
protected string | $resolvableField | The resolvable field associated with the model. | |
bool | $incrementing | Indicates if the IDs are auto-incrementing. | |
protected bool | $respectPublishingStatus | Indicates if we should respect the models publishing status when retrieving it. | |
protected bool | $autoPublishes | Indicates if we should automatically publish the model on save. | |
static protected Dispatcher | $dispatcher | The event dispatcher | |
protected bool | $cachesResults | Determines if we should cache some results. |
Methods
Determine if this object respects publishing statuses when performing queries
Override the publishing status for the model
Perform an action and mutate the given key if $shouldCache is true
Cache the results with the given key if $shouldCache is true
Resolves an instance
Resolves an instance or throws an exception
Resolves multiple instances by their primary fields
Finds an instance by its primary field
Finds an instance by its primary field or throws an exception
Finds multiple instances by their primary fields
No description
Get the api connection for the model.
Get the current connection name for the model.
Set the connection associated with the model.
Retrieves a record by key
Inserts a new record, and returns its id
Updates a record
Deletes a record
Reload a fresh model instance from the database.
Create a new model instance that is existing.
Saves a new model
Create a new instance of the given model.
No description
No description
Retrieves the first matching model or creates it
Retrieves the first model, or creates a new instance if not found
Perform a model update operation.
Perform an action with temporary disabled respectPublishingStatus
Perform a model insert operation.
Sync the original attributes with the current.
Perform any actions that are necessary after the model is saved.
Updates or stores the model
Delete the model from the database.
Destroys one or multiple instances by primary key
Perform the actual delete query on this model instance.
Clone the model into a new, non-existing instance.
Convert the object into something JSON serializable.
Update the model
Updates an exisisting model or creates it
Fill the model with an array of attributes.
Convert the model instance to an array.
Convert the model instance to JSON.
Get the value of the model's route key.
Get the route key for the model.
Retrieve the model for a bound value.
Retrieve the child model for a bound value.
Get the value indicating whether the IDs are incrementing.
No description
No description
No description
No description
Check if the model needs to be booted and if so, do it.
Bootstrap the model and its traits.
Boot all of the bootable traits on the model.
Dynamically retrieve attributes on the model.
Dynamically set attributes on the model.
Initialize any initializable traits on the model.
Get the value of the model's primary key.
Get the primary key for the model.
Set the primary key for the model.
Get the auto-incrementing key type.
Set the data type for the primary key.
Clear the list of booted models so they will be re-booted.
Handle dynamic static method calls into the method.
Convert the model to its string representation.
When a model is being unserialized, check if it needs to be booted.
Shim to make model compatible with HasAttributes trait
No description
No description
Details
in
HasRelation at line 15
string
getRelation()
Gets the relation
in
HasRelation at line 26
int|null
getRelationId()
Gets the relation_id
in
HasRelation at line 39
protected string
getCacheIdentifier(mixed $identifier = null)
Creates a cacheKey
in
HasRelation at line 56
protected
getAllCacheIdentifier()
in
ModelMapper at line 12
protected Closure
getMapper()
in
Queryable at line 39
static protected Builder
makeQueryBuilder($appends = [])
in
Queryable at line 99
bool
respectPublishingStatus()
Determine if this object respects publishing statuses when performing queries
in
Queryable at line 111
static Builder
disregardingPublishingStatus(bool $disregarding = true)
Override the publishing status for the model
in
Queryable at line 125
static Builder
field(...$args)
Adds a field that should be retrieved
in
Queryable at line 138
static Builder
fields(...$args)
Sets which fields to retrieve (default: All fields)
in
Queryable at line 151
static Builder
limit(...$args)
Limits the results to $limit amount of hits
in
Queryable at line 166
static Builder
orderBy(...$args)
Sets the field which to order the results by
in
Queryable at line 179
static Builder
raw(...$args)
Performs a raw query, use carefully.
in
Queryable at line 192
static Builder
publishedAt(...$args)
Performs a 'publishedAt' query
in
Queryable at line 210
static Builder
where(...$args)
Performs a 'where' query
If a closure is passed as the only argument, a new query scope will be created. If $value is omitted, $operator is used as the $value, and the $operator will be set to '='.
in
Queryable at line 224
static Builder
whereIn(...$args)
Queries where field exists in the values
in
Queryable at line 242
static Builder
whereNot(...$args)
Performs a 'whereNot' query
If a closure is passed as the only argument, a new query scope will be created. If $value is omitted, $operator is used as the $value, and the $operator will be set to '='.
in
Queryable at line 257
static
whereBetween(...$args)
in
Queryable at line 272
static
whereNotBetween(...$args)
in
Queryable at line 287
static Paginator
paginate(...$args)
Creates a paginated result
in
Queryable at line 303
static mixed
maybeMutatesCache(string $key, bool $shouldCache, Closure $action)
Perform an action and mutate the given key if $shouldCache is true
in
Queryable at line 320
static Builder
maybeCacheResults(string $key, bool $shouldCache)
Cache the results with the given key if $shouldCache is true
in
Queryable at line 336
static Builder
cacheResults(string $key)
Cache the results with the given key
in
Queryable at line 349
static int
count(...$args)
Get the count of items matching the current query
in
Queryable at line 372
static Builder
query(string $query = '*')
in
Resolvable at line 20
protected
getPrimaryField()
in
Resolvable at line 26
protected
getResolvableField()
in
Resolvable at line 39
static protected mixed
resolvableContext(Closure $context)
Exectures the context if object can be resolved
in
Resolvable at line 55
static Resolvable|null
first()
Retrieves the first instance
in
Resolvable at line 71
static Resolvable
firstOrFail()
Retrieves the first instance or fails
in
Resolvable at line 90
static Resolvable|null
last()
Retrieves the latest instance
in
Resolvable at line 105
static Collection|LazyCollection
all()
Retrieves all instances
in
Resolvable at line 121
static
chunked($chunkSize = null)
at line 812
static QueryableModel|Collection|null
resolve($rawValue, string|null $field = null)
Resolves an instance
in
Resolvable at line 168
static Resolvable|Collection
resolveOrFail(mixed $resolveBy)
Resolves an instance or throws an exception
in
Resolvable at line 185
static Collection
resolveMany(array $resolveBy)
Resolves multiple instances by their primary fields
in
Resolvable at line 198
static Resolvable|Collection|null
find(mixed|array|Collection $findBy)
Finds an instance by its primary field
in
Resolvable at line 225
static Resolvable|Collection
findOrFail(mixed|array $findBy)
Finds an instance by its primary field or throws an exception
in
Resolvable at line 245
static Collection
findMany(array $findBy)
Finds multiple instances by their primary fields
at line 188
__construct(array $attributes = [], bool $boot = true)
at line 205
APIClient
getConnection()
Get the api connection for the model.
at line 215
string|null
getConnectionName()
Get the current connection name for the model.
at line 226
$this
setConnection(string|null $name)
Set the connection associated with the model.
at line 240
protected array|null
performRetrieveRequest(int|null $relationId = null, mixed $key)
Retrieves a record by key
at line 252
protected mixed
performInsertRequest(int|null $relationId = null, array $attributes = [])
Inserts a new record, and returns its id
at line 265
protected void
performUpdateRequest(int|null $relationId = null, mixed $key, array $attributes = [])
Updates a record
at line 277
protected bool
performDeleteRequest(int|null $relationId = null, mixed $key)
Deletes a record
at line 287
QueryableModel|null
fresh()
Reload a fresh model instance from the database.
at line 313
QueryableModel
newFromBuilder(array $attributes = [])
Create a new model instance that is existing.
at line 330
static QueryableModel
create(array $attributes = [])
Saves a new model
at line 346
QueryableModel
newInstance(array $attributes = [], bool $exists = false)
Create a new instance of the given model.
at line 359
array
getTagsAttribute(string|null $tags = null)
at line 368
void
setTagsAttribute(array $tags = [])
at line 380
static QueryableModel
firstOrCreate(array $query, array $with = [])
Retrieves the first matching model or creates it
at line 405
static QueryableModel
firstOrNew(array $attributes = [])
Retrieves the first model, or creates a new instance if not found
at line 419
protected bool
performUpdate()
Perform a model update operation.
at line 458
protected mixed
withIgnoredPublishingStatus(callable $callback)
Perform an action with temporary disabled respectPublishingStatus
at line 473
protected bool
performInsert()
Perform a model insert operation.
at line 509
$this
syncOriginal()
Sync the original attributes with the current.
at line 522
protected void
finishSave()
Perform any actions that are necessary after the model is saved.
at line 534
bool
save()
Updates or stores the model
at line 561
bool|null
delete()
Delete the model from the database.
at line 586
static bool
destroy(mixed|array|Collection ...$identifiers)
Destroys one or multiple instances by primary key
at line 605
protected void
performDeleteOnModel()
Perform the actual delete query on this model instance.
at line 621
QueryableModel
replicate(array $except = null)
Clone the model into a new, non-existing instance.
at line 646
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 657
bool
update(array $attributes = [])
Update the model
at line 673
static QueryableModel
updateOrCreate(array $query, array $with = [])
Updates an exisisting model or creates it
at line 701
$this
fill(array $attributes)
Fill the model with an array of attributes.
at line 724
bool
is(QueryableModel $other)
at line 734
array
toArray()
Convert the model instance to an array.
at line 747
string
toJson(int $options = 0)
Convert the model instance to JSON.
at line 763
mixed
getRouteKey()
Get the value of the model's route key.
at line 773
string
getRouteKeyName()
Get the route key for the model.
at line 786
Model|null
resolveRouteBinding(mixed $rawValue, string|null $field = null)
Retrieve the model for a bound value.
at line 832
Model|null
resolveChildRouteBinding(string $childType, mixed $value, string|null $field)
Retrieve the child model for a bound value.
at line 842
bool
getIncrementing()
Get the value indicating whether the IDs are incrementing.
at line 851
bool
offsetExists(mixed $offset)
at line 860
mixed
offsetGet(mixed $offset)
at line 870
void
offsetSet(mixed $offset, mixed $value)
at line 879
void
offsetUnset(mixed $offset)
at line 889
protected void
bootIfNotBooted()
Check if the model needs to be booted and if so, do it.
at line 906
static protected void
boot()
Bootstrap the model and its traits.
at line 916
static protected void
bootTraits()
Boot all of the bootable traits on the model.
at line 942
mixed
__get(string $key)
Dynamically retrieve attributes on the model.
at line 954
void
__set(string $key, mixed $value)
Dynamically set attributes on the model.
at line 964
protected void
initializeTraits()
Initialize any initializable traits on the model.
at line 976
mixed
getKey()
Get the value of the model's primary key.
at line 986
string
getKeyName()
Get the primary key for the model.
at line 997
$this
setKeyName(string $key)
Set the primary key for the model.
at line 1009
string
getKeyType()
Get the auto-incrementing key type.
at line 1020
$this
setKeyType(string $type)
Set the data type for the primary key.
at line 1032
static void
clearBootedModels()
Clear the list of booted models so they will be re-booted.
at line 1044
static mixed
__callStatic(string $method, array $parameters)
Handle dynamic static method calls into the method.
at line 1054
string
__toString()
Convert the model to its string representation.
at line 1064
void
__wakeup()
When a model is being unserialized, check if it needs to be booted.
at line 1075
static protected void
booting(Closure|string $callback)
Register a booting model event with the dispatcher.
at line 1088
static protected void
booted(Closure|string $callback)
Register a booted model event with the dispatcher.
at line 1101
protected bool
relationLoaded(string $key)
Shim to make model compatible with HasAttributes trait