Defining Models
Introduction
In JCC-Eloquent, each model is a class that extends Model and represents a table record.
Basic rule:
- class name -> table name (plural snake_case by default)
- model properties control behavior (hidden fields, timestamps, soft deletes, mass assignment, etc.)
Generate a model
Use ArtisanNode instead of creating files manually:
Bash
Generated models should live in app/Models.
Basic model definition
TypeScript
By convention this maps to users table.
Customizing table and primary key
TypeScript
Mass assignment control
Use fillable / guarded to control fill(...) and create/update assignments:
TypeScript
Hiding attributes in JSON
TypeScript
toJSON() will omit hidden fields.
Accessors and mutators
Define getter/setter style methods:
TypeScript
Casts and timestamps behavior
Model/base supports static casts and timestamp handling:
TypeScript
Default model behavior:
timestampsenabledprimaryKeyisidsoftDeletesdisabled unless enabled in model strategy
Defining relationships in model
TypeScript
Available relationship helpers include hasOne, hasMany, belongsTo, belongsToMany, and morph variants.
Summary
- Define models by extending
Model. - Prefer generated model files (
make:model) inapp/Models. - Configure table/key/mass-assignment/hidden/accessors directly in the class.
- Add relationship methods to express domain links cleanly.
