class ModelInspector (View source)

Properties

protected Application $app

The Laravel application instance.

protected array<int, string> $relationMethods

The methods that can be called in a model to indicate a relation.

Methods

void
__construct(Application $app)

Create a new model inspector instance.

Model>, database: string, table: string, policy: class-string|Model>>}
inspect(Model>|string $model, string|null $connection = null)

Extract model details for the given model.

Collection<int, array<string, mixed>>
getAttributes(Model $model)

Get the column attributes for the given model.

getVirtualAttributes(Model $model, array $columns)

Get the virtual (non-column) attributes for the given model.

getRelations(Model $model)

Get the relations from the given model.

string|null
getPolicy(Model $model)

Get the first policy associated with this model.

getEvents(Model $model)

Get the events that the model dispatches.

getObservers(Model $model)

Get the observers watching this model.

Collection>
getCollectedBy(Model $model)

Get the collection class being used by the model.

TModel>>
getBuilder(TModel $model)

Get the builder class being used by the model.

Model>
qualifyModel(string $model)

Qualify the given model class base name.

string|null
getCastType(string $column, Model $model)

Get the cast type for the given column.

getCastsWithDates(Model $model)

Get the model casts, including any date casts.

bool
attributeIsHidden(string $attribute, Model $model)

Determine if the given attribute is hidden.

mixed|null
getColumnDefault(array<string, mixed> $column, Model $model)

Get the default value for the given column.

bool
columnIsUnique(string $column, array $indexes)

Determine if the given attribute is unique.

Details

void __construct(Application $app)

Create a new model inspector instance.

Parameters

Application $app

Return Value

void

Model>, database: string, table: string, policy: class-string|Model>>} inspect(Model>|string $model, string|null $connection = null)

Extract model details for the given model.

Parameters

Model>|string $model
string|null $connection

Return Value

Model>, database: string, table: string, policy: class-string|Model>>}

Exceptions

BindingResolutionException

protected Collection<int, array<string, mixed>> getAttributes(Model $model)

Get the column attributes for the given model.

Parameters

Model $model

Return Value

Collection<int, array<string, mixed>>

protected Collection getVirtualAttributes(Model $model, array $columns)

Get the virtual (non-column) attributes for the given model.

Parameters

Model $model
array $columns

Return Value

Collection

protected Collection getRelations(Model $model)

Get the relations from the given model.

Parameters

Model $model

Return Value

Collection

protected string|null getPolicy(Model $model)

Get the first policy associated with this model.

Parameters

Model $model

Return Value

string|null

protected Collection getEvents(Model $model)

Get the events that the model dispatches.

Parameters

Model $model

Return Value

Collection

protected Collection getObservers(Model $model)

Get the observers watching this model.

Parameters

Model $model

Return Value

Collection

Exceptions

BindingResolutionException

protected Collection> getCollectedBy(Model $model)

Get the collection class being used by the model.

Parameters

Model $model

Return Value

Collection>

protected TModel>> getBuilder(TModel $model)

Get the builder class being used by the model.

Parameters

TModel $model

Return Value

TModel>>

protected Model> qualifyModel(string $model)

Qualify the given model class base name.

Parameters

string $model

Return Value

Model>

See also

GeneratorCommand

protected string|null getCastType(string $column, Model $model)

Get the cast type for the given column.

Parameters

string $column
Model $model

Return Value

string|null

protected Collection getCastsWithDates(Model $model)

Get the model casts, including any date casts.

Parameters

Model $model

Return Value

Collection

protected bool attributeIsHidden(string $attribute, Model $model)

Determine if the given attribute is hidden.

Parameters

string $attribute
Model $model

Return Value

bool

protected mixed|null getColumnDefault(array<string, mixed> $column, Model $model)

Get the default value for the given column.

Parameters

array<string, mixed> $column
Model $model

Return Value

mixed|null

protected bool columnIsUnique(string $column, array $indexes)

Determine if the given attribute is unique.

Parameters

string $column
array $indexes

Return Value

bool

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.