|
5 | 5 | use Illuminate\Support\Str; |
6 | 6 | use Illuminate\Validation\Rule; |
7 | 7 | use Illuminate\Container\Container; |
8 | | -use Illuminate\Database\Eloquent\Model; |
9 | 8 | use Illuminate\Contracts\Validation\Factory; |
| 9 | +use Pterodactyl\Models\Traits\WithImmutableDates; |
| 10 | +use Illuminate\Database\Eloquent\Model as IlluminateModel; |
10 | 11 |
|
11 | | -abstract class Validable extends Model |
| 12 | +abstract class Model extends IlluminateModel |
12 | 13 | { |
| 14 | + use WithImmutableDates; |
| 15 | + |
| 16 | + /** |
| 17 | + * Set to true to return immutable Carbon date instances from the model. |
| 18 | + * |
| 19 | + * @var bool |
| 20 | + */ |
| 21 | + protected $immutableDates = false; |
| 22 | + |
13 | 23 | /** |
14 | 24 | * Determines if the model should undergo data validation before it is saved |
15 | 25 | * to the database. |
@@ -47,7 +57,7 @@ protected static function boot() |
47 | 57 |
|
48 | 58 | static::$validatorFactory = Container::getInstance()->make(Factory::class); |
49 | 59 |
|
50 | | - static::saving(function (Validable $model) { |
| 60 | + static::saving(function (Model $model) { |
51 | 61 | return $model->validate(); |
52 | 62 | }); |
53 | 63 | } |
@@ -148,4 +158,19 @@ public function validate() |
148 | 158 | ) |
149 | 159 | )->passes(); |
150 | 160 | } |
| 161 | + |
| 162 | + /** |
| 163 | + * Return a timestamp as DateTime object. |
| 164 | + * |
| 165 | + * @param mixed $value |
| 166 | + * @return \Illuminate\Support\Carbon|\Carbon\CarbonImmutable |
| 167 | + */ |
| 168 | + protected function asDateTime($value) |
| 169 | + { |
| 170 | + if (! $this->immutableDates) { |
| 171 | + return parent::asDateTime($value); |
| 172 | + } |
| 173 | + |
| 174 | + return $this->asImmutableDateTime($value); |
| 175 | + } |
151 | 176 | } |
0 commit comments