Cmd/Ctrl + K

Models

Annabel's database package includes a lightweight model layer for common active record style workflows.

Create a model

Generate a model class in the application's conventional model directory.

Define a model

Configure the table mapping and attributes that may be filled in bulk.

By default, the table name is inferred from the class name, the primary key is id, incrementing keys are enabled, and timestamps use created_at and updated_at.

Query models

Start queries from the model to retrieve records as model instances.

Use the query builder directly when you need explicit SQL-oriented control.

Find and create

Use model shortcuts for primary-key lookup and inserting new records.

Mass assignment respects $fillable and $guarded.

Save and delete

Persist changes on an existing model or remove its record.

Casts

Supported casts include:

  • int / integer
  • real / float / double
  • string
  • bool / boolean
  • array
  • json
  • object
  • datetime / immutable_datetime
  • date
  • decimal:2

Accessors and mutators

Accessors transform values when read, while mutators normalize values before storage.

Relationships

Declare relationships to navigate and query associated models.

Supported relationship helpers are hasOne(), hasMany(), belongsTo(), and belongsToMany().

Eager loading

Eager load relationships when a result set will access the same association repeatedly.

Scopes

Scopes package reusable query constraints behind model methods.

Soft deletes

Enable soft deletes when records should be marked as deleted instead of removed permanently.

Soft-delete helpers include trashed(), restore(), withTrashed(), withoutTrashed(), and onlyTrashed().

Model events

Register model event callbacks for behavior tied to persistence lifecycle changes.

Listeners may return false to halt events that run before persistence.