Added casts properties to all models, re-ordered model properties. Fixes #916

This commit is contained in:
James Brooks
2015-08-22 15:57:53 +01:00
parent 92192232ed
commit a77efc12e0
15 changed files with 182 additions and 94 deletions

View File

@@ -23,16 +23,37 @@ class Component extends Model implements HasPresenter
use SoftDeletes, ValidatingTrait;
/**
* The validation rules.
* List of attributes that have default values.
*
* @var mixed[]
*/
protected $attributes = [
'order' => 0,
'group_id' => 0,
'description' => '',
'link' => '',
];
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
public $rules = [
'name' => 'required|string',
'status' => 'integer|required',
'link' => 'url',
protected $casts = [
'id' => 'int',
'order' => 'int',
'group_id' => 'int',
'description' => 'string',
'link' => 'string',
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* The fillable properties.
*
@@ -49,24 +70,16 @@ class Component extends Model implements HasPresenter
];
/**
* List of attributes that have default values.
* The validation rules.
*
* @var mixed[]
* @var string[]
*/
protected $attributes = [
'order' => 0,
'group_id' => 0,
'description' => '',
'link' => '',
public $rules = [
'name' => 'required|string',
'status' => 'integer|required',
'link' => 'url',
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* Components can belong to a group.
*

View File

@@ -24,8 +24,9 @@ class ComponentGroup extends Model
* @var string[]
*/
protected $casts = [
'id' => 'int',
'name' => 'string',
'order' => 'integer',
'order' => 'int',
];
/**

View File

@@ -23,18 +23,29 @@ class Incident extends Model implements HasPresenter
use SoftDeletes, ValidatingTrait;
/**
* The validation rules.
* The accessors to append to the model's serialized form.
*
* @var string[]
*/
public $rules = [
'component_id' => 'integer',
'name' => 'required',
'status' => 'required|integer',
'visible' => 'required|boolean',
'message' => 'required',
protected $appends = ['human_status'];
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'id' => 'int',
'visible' => 'integer',
];
/**
* The attributes that should be mutated to dates.
*
* @var string[]
*/
protected $dates = ['scheduled_at', 'deleted_at'];
/**
* The fillable properties.
*
@@ -52,26 +63,16 @@ class Incident extends Model implements HasPresenter
];
/**
* The accessors to append to the model's serialized form.
* The validation rules.
*
* @var string[]
*/
protected $appends = ['human_status'];
/**
* The attributes that should be mutated to dates.
*
* @var string[]
*/
protected $dates = ['scheduled_at', 'deleted_at'];
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'visible' => 'integer',
public $rules = [
'component_id' => 'integer',
'name' => 'required',
'status' => 'required|integer',
'visible' => 'required|boolean',
'message' => 'required',
];
/**

View File

@@ -20,13 +20,14 @@ class IncidentTemplate extends Model
use ValidatingTrait;
/**
* The validation rules.
* The attributes that should be casted to native types.
*
* @var string[]
*/
public $rules = [
'name' => 'required',
'template' => 'required',
protected $casts = [
'id' => 'int',
'name' => 'string',
'template' => 'string',
];
/**
@@ -36,6 +37,16 @@ class IncidentTemplate extends Model
*/
protected $fillable = ['name', 'template'];
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required',
'template' => 'required',
];
/**
* Overrides the models boot method.
*/

View File

@@ -37,16 +37,17 @@ class Metric extends Model implements HasPresenter
];
/**
* The validation rules.
* The attributes that should be casted to native types.
*
* @var string[]
*/
public $rules = [
'name' => 'required',
'suffix' => 'required',
'display_chart' => 'boolean',
'default_value' => 'numeric',
'places' => 'numeric|min:0|max:4',
protected $casts = [
'id' => 'int',
'name' => 'string',
'display_chart' => 'bool',
'default_value' => 'int',
'calc_type' => 'int',
'places' => 'int',
];
/**
@@ -64,6 +65,19 @@ class Metric extends Model implements HasPresenter
'places',
];
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'name' => 'required',
'suffix' => 'required',
'display_chart' => 'boolean',
'default_value' => 'numeric',
'places' => 'numeric|min:0|max:4',
];
/**
* The relations to eager load on every query.
*

View File

@@ -20,6 +20,17 @@ class MetricPoint extends Model implements HasPresenter
{
use ValidatingTrait;
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'id' => 'int',
'metric_id' => 'int',
'value' => 'int',
];
/**
* The attributes that are mass assignable.
*

View File

@@ -15,6 +15,17 @@ use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'id' => 'int',
'name' => 'string',
'value' => 'string',
];
/**
* The fillable properties.
*

View File

@@ -21,21 +21,16 @@ class Subscriber extends Model implements HasPresenter
use ValidatingTrait;
/**
* The validation rules.
* The attributes that should be casted to native types.
*
* @var string[]
*/
public $rules = [
'email' => 'required|email',
protected $casts = [
'id' => 'int',
'email' => 'string',
'verify_code' => 'string',
];
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = ['email'];
/**
* The attributes that should be mutated to dates.
*
@@ -44,13 +39,19 @@ class Subscriber extends Model implements HasPresenter
protected $dates = ['verified_at'];
/**
* The attributes that should be casted to native types.
* The fillable properties.
*
* @var string[]
*/
protected $casts = [
'email' => 'string',
'verify_code' => 'string',
protected $fillable = ['email'];
/**
* The validation rules.
*
* @var string[]
*/
public $rules = [
'email' => 'required|email',
];
/**

View File

@@ -16,6 +16,16 @@ use Illuminate\Support\Str;
class Tag extends Model
{
/**
* The attributes that should be casted to native types.
*
* @var string[]
*/
protected $casts = [
'id' => 'int',
'name' => 'string',
];
/**
* The fillable properties.
*

View File

@@ -25,16 +25,27 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
use Authenticatable, CanResetPassword, ValidatingTrait;
/**
* The validation rules.
* The attributes that should be casted to native types.
*
* @var string[]
*/
public $rules = [
'username' => ['required', 'regex:/\A(?!.*[:;]-\))[ -~]+\z/'],
'email' => 'required|email',
'password' => 'required',
protected $casts = [
'id' => 'int',
'username' => 'string',
'email' => 'string',
'google_2fa_secret' => 'string',
'api_key' => 'string',
'active' => 'bool',
'level' => 'int',
];
/**
* The properties that cannot be mass assigned.
*
* @var string[]
*/
protected $guarded = [];
/**
* The hidden properties.
*
@@ -45,11 +56,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
protected $hidden = ['password', 'remember_token', 'google_2fa_secret'];
/**
* The properties that cannot be mass assigned.
* The validation rules.
*
* @var string[]
*/
protected $guarded = [];
public $rules = [
'username' => ['required', 'regex:/\A(?!.*[:;]-\))[ -~]+\z/'],
'email' => 'required|email',
'password' => 'required',
];
/**
* Overrides the models boot method.