Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created June 27, 2020 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilcorrea/b1663acc85b16590453ecc9b803a0e78 to your computer and use it in GitHub Desktop.
Save wilcorrea/b1663acc85b16590453ecc9b803a0e78 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace Source\Domains\General;
use Devitools\Persistence\AbstractModel;
/**
* Class Category
*
* @package Source\Domains\General
*/
class Category extends AbstractModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'categories';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'description',
'active',
];
/**
* @var array
*/
protected $rules = [
'name' => ['required'],
];
/**
* @var array
*/
protected $casts = [
'active' => 'boolean',
];
/**
* @return string
*/
public function domain(): string
{
return 'general.category';
}
}
<?php
declare(strict_types=1);
namespace Source\Domains\General;
use Devitools\Agnostic\Schema;
/**
* Class Category
*
* @package Source\Domains\General
*/
class CategorySchema extends Schema
{
/**
* The table associated with the model.
*
* @var string
*/
protected function source(): string
{
return 'categories';
}
/**
* @return string
*/
public static function domain(): string
{
return 'general.category';
}
/**
* @return Schema
*/
protected function construct(): Schema
{
$this->addField('name')
->fieldIsString()
->validationRequired();
$this->addField('description')
->fieldIsString();
$this->addField('active')
->fieldIsBoolean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment