Configuration
Model Configuration
WPZylos Model is configured through model class properties. There is no external configuration file — each model declares its own settings.
Table Configuration
Table Name
class Order extends Model
{
// Table name without WordPress prefix
// Resolves to: wp_orders (or custom prefix)
protected static string $table = 'orders';
}
Primary Key
class Order extends Model
{
// Default is 'id'
protected static string $primaryKey = 'order_id';
}
Mass Assignment
Whitelist (fillable)
Only listed attributes can be mass-assigned:
protected array $fillable = ['name', 'email', 'role'];
Blacklist (guarded)
Listed attributes are protected from mass-assignment:
protected array $guarded = ['id', 'is_admin'];
Guard All
protected array $guarded = ['*'];
Attribute Casting
protected array $casts = [
'age' => 'int', // or 'integer'
'price' => 'float', // or 'double', 'real'
'is_active' => 'bool', // or 'boolean'
'name' => 'string',
'tags' => 'array',
'metadata' => 'json',
'created_at' => 'datetime',
];
| Cast Type | PHP Type | DB Serialization |
|---|---|---|
int / integer | int | Raw value |
float / double / real | float | Raw value |
bool / boolean | bool | 0 or 1 |
string | string | Raw value |
array | array | JSON string |
json | array | JSON string |
datetime | DateTimeImmutable | Y-m-d H:i:s |
Timestamp Configuration
Enable/Disable
// Enable (default)
protected bool $timestamps = true;
// Disable
protected bool $timestamps = false;
Customize Column Names
protected ?string $createdAtColumn = 'date_created';
protected ?string $updatedAtColumn = 'date_modified';
Disable One Column
protected ?string $createdAtColumn = null; // No created_at
protected ?string $updatedAtColumn = 'updated_at'; // Keep updated_at
Serialization
Hidden Attributes
Attributes excluded from toArray() and toJson():
protected array $hidden = ['password', 'secret_key', 'internal_notes'];
Soft Deletes Configuration
Enable
use WPZylos\Framework\Model\Concerns\SoftDeletes;
class Article extends Model
{
use SoftDeletes;
}
Custom Deleted Column
protected string $deletedAtColumn = 'removed_at';
Service Provider Configuration
The ModelServiceProvider requires no configuration. It automatically:
- Registers
ModelResolverasmodel.resolversingleton - Injects the application instance into
Model::setApplication()
// Registration — that's it
$app->register(new ModelServiceProvider());