Use built in casts
This commit is contained in:
parent
4cc123aed5
commit
0dacfc31ac
@ -26,12 +26,11 @@ class AuditLog extends Model
|
||||
|
||||
protected $table = 'audit_logs';
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
protected $casts = [
|
||||
'is_system' => 'bool',
|
||||
'device' => 'array',
|
||||
'metadata' => 'array',
|
||||
'created_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
protected $guarded = [
|
||||
|
@ -36,15 +36,16 @@ class Backup extends Model
|
||||
|
||||
protected $table = 'backups';
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'is_successful' => 'bool',
|
||||
'is_locked' => 'bool',
|
||||
'ignored_files' => 'array',
|
||||
'bytes' => 'int',
|
||||
'completed_at' => 'datetime',
|
||||
'completed_at' => 'immutable_datetime',
|
||||
'created_at' => 'immutable_datetime',
|
||||
'updated_at' => 'immutable_datetime',
|
||||
'deleted_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
protected $attributes = [
|
||||
|
@ -25,8 +25,6 @@ class DatabaseHost extends Model
|
||||
*/
|
||||
public const RESOURCE_NAME = 'database_host';
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
@ -51,6 +49,8 @@ class DatabaseHost extends Model
|
||||
'id' => 'integer',
|
||||
'max_databases' => 'integer',
|
||||
'node_id' => 'integer',
|
||||
'created_at' => 'immutable_datetime',
|
||||
'updated_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -38,8 +38,6 @@ class EggVariable extends Model
|
||||
*/
|
||||
public const RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
@ -57,6 +55,8 @@ class EggVariable extends Model
|
||||
'egg_id' => 'integer',
|
||||
'user_viewable' => 'bool',
|
||||
'user_editable' => 'bool',
|
||||
'created_at' => 'immutable_datetime',
|
||||
'updated_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
public static array $validationRules = [
|
||||
|
@ -19,11 +19,6 @@ abstract class Model extends IlluminateModel
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Set to true to return immutable Carbon date instances from the model.
|
||||
*/
|
||||
protected bool $immutableDates = false;
|
||||
|
||||
/**
|
||||
* Determines if the model should undergo data validation before it is saved
|
||||
* to the database.
|
||||
@ -160,18 +155,4 @@ abstract class Model extends IlluminateModel
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a timestamp as DateTime object.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function asDateTime($value): Carbon|CarbonImmutable
|
||||
{
|
||||
if (!$this->immutableDates) {
|
||||
return parent::asDateTime($value);
|
||||
}
|
||||
|
||||
return parent::asDateTime($value)->toImmutable();
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,14 @@ class RecoveryToken extends Model
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
public static array $validationRules = [
|
||||
'token' => 'required|string',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'created_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
@ -22,8 +22,6 @@ class ServerVariable extends Model
|
||||
*/
|
||||
public const RESOURCE_NAME = 'server_variable';
|
||||
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
protected $table = 'server_variables';
|
||||
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
@ -31,6 +29,8 @@ class ServerVariable extends Model
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
'variable_id' => 'integer',
|
||||
'created_at' => 'immutable_datetime',
|
||||
'updated_at' => 'immutable_datetime',
|
||||
];
|
||||
|
||||
public static array $validationRules = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user