-
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;
}$user = (new User())->find(42); // object or null$users = (new User())->all(); // array of objects$users = (new User())->where('active', true)->get();$id = (new User())->insert([
'name' => 'John',
'email' => 'john@example.com',
]);(new User())->update(42, ['name' => 'Jane']);(new User())->delete(42);$qb = (new User())->query(); // Get the underlying QueryBuilder
$user = (new User())->query()->where('email', 'john@example.com')->first();