Models: Use explicit casts and default attribute values
This commit is contained in:
parent
b23b89cc7a
commit
a95fc0fbd1
|
@ -42,10 +42,17 @@ class News extends BaseModel
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
'user_id' => 'integer',
|
||||||
'is_meeting' => 'boolean',
|
'is_meeting' => 'boolean',
|
||||||
'is_pinned' => 'boolean',
|
'is_pinned' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var array Default attributes */
|
||||||
|
protected $attributes = [
|
||||||
|
'is_meeting' => false,
|
||||||
|
'is_pinned' => false,
|
||||||
|
];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'title',
|
'title',
|
||||||
|
|
|
@ -34,6 +34,12 @@ class NewsComment extends BaseModel
|
||||||
/** @var bool Enable timestamps */
|
/** @var bool Enable timestamps */
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $casts = [
|
||||||
|
'user_id' => 'integer',
|
||||||
|
'news_id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'news_id',
|
'news_id',
|
||||||
|
|
|
@ -34,6 +34,11 @@ class OAuth extends BaseModel
|
||||||
/** @var bool Enable timestamps */
|
/** @var bool Enable timestamps */
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $casts = [
|
||||||
|
'user_id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
protected $dates = [
|
protected $dates = [
|
||||||
'expires_at',
|
'expires_at',
|
||||||
|
|
|
@ -37,6 +37,13 @@ class Schedule extends BaseModel
|
||||||
/** @var bool enable timestamps */
|
/** @var bool enable timestamps */
|
||||||
public $timestamps = true;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $casts = [
|
||||||
|
'shift_type' => 'integer',
|
||||||
|
'minutes_before' => 'integer',
|
||||||
|
'minutes_after' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/** @var array Values that are mass assignable */
|
/** @var array Values that are mass assignable */
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
|
|
|
@ -28,6 +28,12 @@ class ScheduleShift extends BaseModel
|
||||||
/** @var array Values that are mass assignable */
|
/** @var array Values that are mass assignable */
|
||||||
protected $fillable = ['shift_id', 'schedule_id', 'guid'];
|
protected $fillable = ['shift_id', 'schedule_id', 'guid'];
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $casts = [
|
||||||
|
'shift_id' => 'integer',
|
||||||
|
'schedule_id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo
|
* @return BelongsTo
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -16,6 +16,11 @@ abstract class HasUserModel extends BaseModel
|
||||||
'user_id',
|
'user_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
protected $casts = [
|
||||||
|
'user_id' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
/** The relationships that should be touched on save */
|
/** The relationships that should be touched on save */
|
||||||
protected $touches = ['user'];
|
protected $touches = ['user'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,18 @@ class State extends HasUserModel
|
||||||
/** @var string The table associated with the model */
|
/** @var string The table associated with the model */
|
||||||
protected $table = 'users_state';
|
protected $table = 'users_state';
|
||||||
|
|
||||||
/** @var array The attributes that should be mutated to dates */
|
/** @var array Default attributes */
|
||||||
protected $dates = [
|
protected $attributes = [
|
||||||
'arrival_date',
|
'arrived' => false,
|
||||||
|
'active' => false,
|
||||||
|
'force_active' => false,
|
||||||
|
'got_shirt' => false,
|
||||||
|
'got_voucher' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
'user_id' => 'integer',
|
||||||
'arrived' => 'boolean',
|
'arrived' => 'boolean',
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
'force_active' => 'boolean',
|
'force_active' => 'boolean',
|
||||||
|
@ -42,6 +47,11 @@ class State extends HasUserModel
|
||||||
'got_voucher' => 'integer',
|
'got_voucher' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** @var array The attributes that should be mutated to dates */
|
||||||
|
protected $dates = [
|
||||||
|
'arrival_date',
|
||||||
|
];
|
||||||
|
|
||||||
/** The attributes that are mass assignable */
|
/** The attributes that are mass assignable */
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
|
|
|
@ -15,6 +15,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||||
trait UsesUserModel
|
trait UsesUserModel
|
||||||
{
|
{
|
||||||
// protected $fillable = ['user_id'];
|
// protected $fillable = ['user_id'];
|
||||||
|
// protected $casts = ['user_id' => 'integer];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo
|
* @return BelongsTo
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Worklog extends BaseModel
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'user_id' => 'integer',
|
'user_id' => 'integer',
|
||||||
'creator_id' => 'integer',
|
'creator_id' => 'integer',
|
||||||
|
'hours' => 'float',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** The attributes that are mass assignable. */
|
/** The attributes that are mass assignable. */
|
||||||
|
|
Loading…
Reference in New Issue