1. Go to this page and download the library: Download ovargas/fluentrules library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use ovargas\fluentrules\Attribute;
use ovargas\fluentrules\RuleBuilder;
public function rules()
{
return RuleBuilder::rules([
Attribute::create('code')->string(2)->notNull()->unique(),
Attribute::create('name')->string()->notNull(),
Attribute::create('population')->integer()->skipOnEmpty(false),
Attribute::create('status')->string()->defaultValue('active')->in(['active', 'inactive', 'deleted']),
]);
}
$this->createTable('{{%location}}', [
'id' => $this->primaryKey(),
'name' => $this->string()->notNull(),
'age' => $this->integer()->append('CHECK (age >= 18 AND age <= 99)'),
'status' => $this->string()->defaultValue('active')->check("status IN ('active', 'inactive', 'deleted')"),
]);