Models: Use explicit casts and default attribute values

main
Igor Scheller 3 years ago committed by msquare
parent b23b89cc7a
commit a95fc0fbd1

@ -42,10 +42,17 @@ class News extends BaseModel
/** @var array */
protected $casts = [
'user_id' => 'integer',
'is_meeting' => 'boolean',
'is_pinned' => 'boolean',
];
/** @var array Default attributes */
protected $attributes = [
'is_meeting' => false,
'is_pinned' => false,
];
/** @var array */
protected $fillable = [
'title',

@ -34,6 +34,12 @@ class NewsComment extends BaseModel
/** @var bool Enable timestamps */
public $timestamps = true;
/** @var string[] */
protected $casts = [
'user_id' => 'integer',
'news_id' => 'integer',
];
/** @var string[] */
protected $fillable = [
'news_id',

@ -34,6 +34,11 @@ class OAuth extends BaseModel
/** @var bool Enable timestamps */
public $timestamps = true;
/** @var string[] */
protected $casts = [
'user_id' => 'integer',
];
/** @var string[] */
protected $dates = [
'expires_at',

@ -37,6 +37,13 @@ class Schedule extends BaseModel
/** @var bool enable timestamps */
public $timestamps = true;
/** @var string[] */
protected $casts = [
'shift_type' => 'integer',
'minutes_before' => 'integer',
'minutes_after' => 'integer',
];
/** @var array Values that are mass assignable */
protected $fillable = [
'name',

@ -28,6 +28,12 @@ class ScheduleShift extends BaseModel
/** @var array Values that are mass assignable */
protected $fillable = ['shift_id', 'schedule_id', 'guid'];
/** @var array */
protected $casts = [
'shift_id' => 'integer',
'schedule_id' => 'integer',
];
/**
* @return BelongsTo
*/

@ -16,6 +16,11 @@ abstract class HasUserModel extends BaseModel
'user_id',
];
/** @var string[] */
protected $casts = [
'user_id' => 'integer',
];
/** The relationships that should be touched on save */
protected $touches = ['user'];
}

@ -28,13 +28,18 @@ class State extends HasUserModel
/** @var string The table associated with the model */
protected $table = 'users_state';
/** @var array The attributes that should be mutated to dates */
protected $dates = [
'arrival_date',
/** @var array Default attributes */
protected $attributes = [
'arrived' => false,
'active' => false,
'force_active' => false,
'got_shirt' => false,
'got_voucher' => 0,
];
/** @var array */
protected $casts = [
'user_id' => 'integer',
'arrived' => 'boolean',
'active' => 'boolean',
'force_active' => 'boolean',
@ -42,6 +47,11 @@ class State extends HasUserModel
'got_voucher' => 'integer',
];
/** @var array The attributes that should be mutated to dates */
protected $dates = [
'arrival_date',
];
/** The attributes that are mass assignable */
protected $fillable = [
'user_id',

@ -15,6 +15,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
trait UsesUserModel
{
// protected $fillable = ['user_id'];
// protected $casts = ['user_id' => 'integer];
/**
* @return BelongsTo

@ -43,6 +43,7 @@ class Worklog extends BaseModel
protected $casts = [
'user_id' => 'integer',
'creator_id' => 'integer',
'hours' => 'float',
];
/** The attributes that are mass assignable. */

Loading…
Cancel
Save