Docs/API Reference/Database

Database API: models

Model exposes these important static fields in the inspected source:

1 min read

Static model configuration#

Model exposes these important static fields in the inspected source:

  • table: string
  • primaryKey = "id"
  • autoUuid = true
  • timestamps: boolean | string[] = true
  • casts: Record<string, CastType> = {}
  • softDeletes = false
  • deletedAtColumn = "deleted_at"
  • hidden: string[] = []
  • fillable: string[] = []
  • guarded: string[] = []
  • globalScopes

Static helpers#

The base model implements query, withTrashed, onlyTrashed, find, findOrFail, all, count, where, create, forceCreate, firstOrCreate, firstOrNew and updateOrCreate. The full source also contains attribute/fill/save/delete methods and relation helpers; consult the declaration shipped with the installed package for complete overloads.

Instance behavior#

Models keep current and original attributes for dirty tracking, support save() and serialize through toJSON(). A proxy enables direct attribute access. Internal properties beginning with _ and key model methods receive special handling, so avoid naming application attributes after internal model methods.

Mass assignment#

Use fillable as an allowlist or guarded as a denylist. Do not pass raw request objects directly into create() or fill(). Construct an explicit validated DTO before persistence.

veap
Preparing0%