-
Notifications
You must be signed in to change notification settings - Fork 0
Model
Laureano F. Lamonega edited this page Jul 17, 2026
·
4 revisions
The base model provides CRUD operations and automatic table name guessing.
use Antimonial\Model\Model;
class User extends Model {}PascalCase class names are converted to snake_case plural:
| Class | Table Name |
|---|---|
User |
users |
BlogPost |
blog_posts |
Category |
categorys (naive — set $table explicitly for irregular plurals)
|
To use a custom table name, override the $table property:
class Category extends Model
{
protected string $table = 'categories';
}The default primary key is id. Override with:
class User extends Model
{
protected string $primaryKey = 'user_id';
}Enable automatic created_at / updated_at:
class User extends Model
{
protected bool $timestamps = true;
}All CRUD methods support both static and instance syntax:
$user = User::find(42); // static (preferred)
$user = (new User())->find(42); // instance — also works$users = User::all();$users = User::where('active', true)->orderBy('name')->get();$id = User::insert([ // static
'name' => 'John',
'email' => 'john@example.com',
]);User::update(42, ['name' => 'Jane']);User::delete(42);$qb = User::query(); // Get the underlying QueryBuilder
$user = User::query()->where('email', 'john@example.com')->first();