-
Notifications
You must be signed in to change notification settings - Fork 599
/
Model.php
2433 lines (2116 loc) · 63.5 KB
/
Model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Illuminate\Database\Eloquent;
use ArrayAccess;
use Illuminate\Contracts\Broadcasting\HasBroadcastChannel;
use Illuminate\Contracts\Queue\QueueableCollection;
use Illuminate\Contracts\Queue\QueueableEntity;
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Database\ConnectionResolverInterface as Resolver;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\ForwardsCalls;
use JsonException;
use JsonSerializable;
use LogicException;
use Stringable;
abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToString, HasBroadcastChannel, Jsonable, JsonSerializable, QueueableEntity, Stringable, UrlRoutable
{
use Concerns\HasAttributes,
Concerns\HasEvents,
Concerns\HasGlobalScopes,
Concerns\HasRelationships,
Concerns\HasTimestamps,
Concerns\HasUniqueIds,
Concerns\HidesAttributes,
Concerns\GuardsAttributes,
Concerns\PreventsCircularRecursion,
ForwardsCalls;
/** @use HasCollection<\Illuminate\Database\Eloquent\Collection<array-key, static>> */
use HasCollection;
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection;
/**
* The table associated with the model.
*
* @var string|null
*/
protected $table;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'int';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = true;
/**
* The relations to eager load on every query.
*
* @var array
*/
protected $with = [];
/**
* The relationship counts that should be eager loaded on every query.
*
* @var array
*/
protected $withCount = [];
/**
* Indicates whether lazy loading will be prevented on this model.
*
* @var bool
*/
public $preventsLazyLoading = false;
/**
* The number of models to return for pagination.
*
* @var int
*/
protected $perPage = 15;
/**
* Indicates if the model exists.
*
* @var bool
*/
public $exists = false;
/**
* Indicates if the model was inserted during the object's lifecycle.
*
* @var bool
*/
public $wasRecentlyCreated = false;
/**
* Indicates that the object's string representation should be escaped when __toString is invoked.
*
* @var bool
*/
protected $escapeWhenCastingToString = false;
/**
* The connection resolver instance.
*
* @var \Illuminate\Database\ConnectionResolverInterface
*/
protected static $resolver;
/**
* The event dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher|null
*/
protected static $dispatcher;
/**
* The array of booted models.
*
* @var array
*/
protected static $booted = [];
/**
* The array of trait initializers that will be called on each new instance.
*
* @var array
*/
protected static $traitInitializers = [];
/**
* The array of global scopes on the model.
*
* @var array
*/
protected static $globalScopes = [];
/**
* The list of models classes that should not be affected with touch.
*
* @var array
*/
protected static $ignoreOnTouch = [];
/**
* Indicates whether lazy loading should be restricted on all models.
*
* @var bool
*/
protected static $modelsShouldPreventLazyLoading = false;
/**
* The callback that is responsible for handling lazy loading violations.
*
* @var callable|null
*/
protected static $lazyLoadingViolationCallback;
/**
* Indicates if an exception should be thrown instead of silently discarding non-fillable attributes.
*
* @var bool
*/
protected static $modelsShouldPreventSilentlyDiscardingAttributes = false;
/**
* The callback that is responsible for handling discarded attribute violations.
*
* @var callable|null
*/
protected static $discardedAttributeViolationCallback;
/**
* Indicates if an exception should be thrown when trying to access a missing attribute on a retrieved model.
*
* @var bool
*/
protected static $modelsShouldPreventAccessingMissingAttributes = false;
/**
* The callback that is responsible for handling missing attribute violations.
*
* @var callable|null
*/
protected static $missingAttributeViolationCallback;
/**
* Indicates if broadcasting is currently enabled.
*
* @var bool
*/
protected static $isBroadcasting = true;
/**
* The Eloquent query builder class to use for the model.
*
* @var class-string<\Illuminate\Database\Eloquent\Builder<*>>
*/
protected static string $builder = Builder::class;
/**
* The Eloquent collection class to use for the model.
*
* @var class-string<\Illuminate\Database\Eloquent\Collection<*, *>>
*/
protected static string $collectionClass = Collection::class;
/**
* The name of the "created at" column.
*
* @var string|null
*/
const CREATED_AT = 'created_at';
/**
* The name of the "updated at" column.
*
* @var string|null
*/
const UPDATED_AT = 'updated_at';
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
$this->bootIfNotBooted();
$this->initializeTraits();
$this->syncOriginal();
$this->fill($attributes);
}
/**
* Check if the model needs to be booted and if so, do it.
*
* @return void
*/
protected function bootIfNotBooted()
{
if (! isset(static::$booted[static::class])) {
static::$booted[static::class] = true;
$this->fireModelEvent('booting', false);
static::booting();
static::boot();
static::booted();
$this->fireModelEvent('booted', false);
}
}
/**
* Perform any actions required before the model boots.
*
* @return void
*/
protected static function booting()
{
//
}
/**
* Bootstrap the model and its traits.
*
* @return void
*/
protected static function boot()
{
static::bootTraits();
}
/**
* Boot all of the bootable traits on the model.
*
* @return void
*/
protected static function bootTraits()
{
$class = static::class;
$booted = [];
static::$traitInitializers[$class] = [];
foreach (class_uses_recursive($class) as $trait) {
$method = 'boot'.class_basename($trait);
if (method_exists($class, $method) && ! in_array($method, $booted)) {
forward_static_call([$class, $method]);
$booted[] = $method;
}
if (method_exists($class, $method = 'initialize'.class_basename($trait))) {
static::$traitInitializers[$class][] = $method;
static::$traitInitializers[$class] = array_unique(
static::$traitInitializers[$class]
);
}
}
}
/**
* Initialize any initializable traits on the model.
*
* @return void
*/
protected function initializeTraits()
{
foreach (static::$traitInitializers[static::class] as $method) {
$this->{$method}();
}
}
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
//
}
/**
* Clear the list of booted models so they will be re-booted.
*
* @return void
*/
public static function clearBootedModels()
{
static::$booted = [];
static::$globalScopes = [];
}
/**
* Disables relationship model touching for the current class during given callback scope.
*
* @param callable $callback
* @return void
*/
public static function withoutTouching(callable $callback)
{
static::withoutTouchingOn([static::class], $callback);
}
/**
* Disables relationship model touching for the given model classes during given callback scope.
*
* @param array $models
* @param callable $callback
* @return void
*/
public static function withoutTouchingOn(array $models, callable $callback)
{
static::$ignoreOnTouch = array_values(array_merge(static::$ignoreOnTouch, $models));
try {
$callback();
} finally {
static::$ignoreOnTouch = array_values(array_diff(static::$ignoreOnTouch, $models));
}
}
/**
* Determine if the given model is ignoring touches.
*
* @param string|null $class
* @return bool
*/
public static function isIgnoringTouch($class = null)
{
$class = $class ?: static::class;
if (! get_class_vars($class)['timestamps'] || ! $class::UPDATED_AT) {
return true;
}
foreach (static::$ignoreOnTouch as $ignoredClass) {
if ($class === $ignoredClass || is_subclass_of($class, $ignoredClass)) {
return true;
}
}
return false;
}
/**
* Indicate that models should prevent lazy loading, silently discarding attributes, and accessing missing attributes.
*
* @param bool $shouldBeStrict
* @return void
*/
public static function shouldBeStrict(bool $shouldBeStrict = true)
{
static::preventLazyLoading($shouldBeStrict);
static::preventSilentlyDiscardingAttributes($shouldBeStrict);
static::preventAccessingMissingAttributes($shouldBeStrict);
}
/**
* Prevent model relationships from being lazy loaded.
*
* @param bool $value
* @return void
*/
public static function preventLazyLoading($value = true)
{
static::$modelsShouldPreventLazyLoading = $value;
}
/**
* Register a callback that is responsible for handling lazy loading violations.
*
* @param callable|null $callback
* @return void
*/
public static function handleLazyLoadingViolationUsing(?callable $callback)
{
static::$lazyLoadingViolationCallback = $callback;
}
/**
* Prevent non-fillable attributes from being silently discarded.
*
* @param bool $value
* @return void
*/
public static function preventSilentlyDiscardingAttributes($value = true)
{
static::$modelsShouldPreventSilentlyDiscardingAttributes = $value;
}
/**
* Register a callback that is responsible for handling discarded attribute violations.
*
* @param callable|null $callback
* @return void
*/
public static function handleDiscardedAttributeViolationUsing(?callable $callback)
{
static::$discardedAttributeViolationCallback = $callback;
}
/**
* Prevent accessing missing attributes on retrieved models.
*
* @param bool $value
* @return void
*/
public static function preventAccessingMissingAttributes($value = true)
{
static::$modelsShouldPreventAccessingMissingAttributes = $value;
}
/**
* Register a callback that is responsible for handling missing attribute violations.
*
* @param callable|null $callback
* @return void
*/
public static function handleMissingAttributeViolationUsing(?callable $callback)
{
static::$missingAttributeViolationCallback = $callback;
}
/**
* Execute a callback without broadcasting any model events for all model types.
*
* @param callable $callback
* @return mixed
*/
public static function withoutBroadcasting(callable $callback)
{
$isBroadcasting = static::$isBroadcasting;
static::$isBroadcasting = false;
try {
return $callback();
} finally {
static::$isBroadcasting = $isBroadcasting;
}
}
/**
* Fill the model with an array of attributes.
*
* @param array $attributes
* @return $this
*
* @throws \Illuminate\Database\Eloquent\MassAssignmentException
*/
public function fill(array $attributes)
{
$totallyGuarded = $this->totallyGuarded();
$fillable = $this->fillableFromArray($attributes);
foreach ($fillable as $key => $value) {
// The developers may choose to place some attributes in the "fillable" array
// which means only those attributes may be set through mass assignment to
// the model, and all others will just get ignored for security reasons.
if ($this->isFillable($key)) {
$this->setAttribute($key, $value);
} elseif ($totallyGuarded || static::preventsSilentlyDiscardingAttributes()) {
if (isset(static::$discardedAttributeViolationCallback)) {
call_user_func(static::$discardedAttributeViolationCallback, $this, [$key]);
} else {
throw new MassAssignmentException(sprintf(
'Add [%s] to fillable property to allow mass assignment on [%s].',
$key, get_class($this)
));
}
}
}
if (count($attributes) !== count($fillable) &&
static::preventsSilentlyDiscardingAttributes()) {
$keys = array_diff(array_keys($attributes), array_keys($fillable));
if (isset(static::$discardedAttributeViolationCallback)) {
call_user_func(static::$discardedAttributeViolationCallback, $this, $keys);
} else {
throw new MassAssignmentException(sprintf(
'Add fillable property [%s] to allow mass assignment on [%s].',
implode(', ', $keys),
get_class($this)
));
}
}
return $this;
}
/**
* Fill the model with an array of attributes. Force mass assignment.
*
* @param array $attributes
* @return $this
*/
public function forceFill(array $attributes)
{
return static::unguarded(fn () => $this->fill($attributes));
}
/**
* Qualify the given column name by the model's table.
*
* @param string $column
* @return string
*/
public function qualifyColumn($column)
{
if (str_contains($column, '.')) {
return $column;
}
return $this->getTable().'.'.$column;
}
/**
* Qualify the given columns with the model's table.
*
* @param array $columns
* @return array
*/
public function qualifyColumns($columns)
{
return (new BaseCollection($columns))
->map(fn ($column) => $this->qualifyColumn($column))
->all();
}
/**
* Create a new instance of the given model.
*
* @param array $attributes
* @param bool $exists
* @return static
*/
public function newInstance($attributes = [], $exists = false)
{
// This method just provides a convenient way for us to generate fresh model
// instances of this current model. It is particularly useful during the
// hydration of new objects via the Eloquent query builder instances.
$model = new static;
$model->exists = $exists;
$model->setConnection(
$this->getConnectionName()
);
$model->setTable($this->getTable());
$model->mergeCasts($this->casts);
$model->fill((array) $attributes);
return $model;
}
/**
* Create a new model instance that is existing.
*
* @param array $attributes
* @param string|null $connection
* @return static
*/
public function newFromBuilder($attributes = [], $connection = null)
{
$model = $this->newInstance([], true);
$model->setRawAttributes((array) $attributes, true);
$model->setConnection($connection ?: $this->getConnectionName());
$model->fireModelEvent('retrieved', false);
return $model;
}
/**
* Begin querying the model on a given connection.
*
* @param string|null $connection
* @return \Illuminate\Database\Eloquent\Builder<static>
*/
public static function on($connection = null)
{
// First we will just create a fresh instance of this model, and then we can set the
// connection on the model so that it is used for the queries we execute, as well
// as being set on every relation we retrieve without a custom connection name.
$instance = new static;
$instance->setConnection($connection);
return $instance->newQuery();
}
/**
* Begin querying the model on the write connection.
*
* @return \Illuminate\Database\Eloquent\Builder<static>
*/
public static function onWriteConnection()
{
return static::query()->useWritePdo();
}
/**
* Get all of the models from the database.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Collection<int, static>
*/
public static function all($columns = ['*'])
{
return static::query()->get(
is_array($columns) ? $columns : func_get_args()
);
}
/**
* Begin querying a model with eager loading.
*
* @param array|string $relations
* @return \Illuminate\Database\Eloquent\Builder<static>
*/
public static function with($relations)
{
return static::query()->with(
is_string($relations) ? func_get_args() : $relations
);
}
/**
* Eager load relations on the model.
*
* @param array|string $relations
* @return $this
*/
public function load($relations)
{
$query = $this->newQueryWithoutRelationships()->with(
is_string($relations) ? func_get_args() : $relations
);
$query->eagerLoadRelations([$this]);
return $this;
}
/**
* Eager load relationships on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @return $this
*/
public function loadMorph($relation, $relations)
{
if (! $this->{$relation}) {
return $this;
}
$className = get_class($this->{$relation});
$this->{$relation}->load($relations[$className] ?? []);
return $this;
}
/**
* Eager load relations on the model if they are not already eager loaded.
*
* @param array|string $relations
* @return $this
*/
public function loadMissing($relations)
{
$relations = is_string($relations) ? func_get_args() : $relations;
$this->newCollection([$this])->loadMissing($relations);
return $this;
}
/**
* Eager load relation's column aggregations on the model.
*
* @param array|string $relations
* @param string $column
* @param string|null $function
* @return $this
*/
public function loadAggregate($relations, $column, $function = null)
{
$this->newCollection([$this])->loadAggregate($relations, $column, $function);
return $this;
}
/**
* Eager load relation counts on the model.
*
* @param array|string $relations
* @return $this
*/
public function loadCount($relations)
{
$relations = is_string($relations) ? func_get_args() : $relations;
return $this->loadAggregate($relations, '*', 'count');
}
/**
* Eager load relation max column values on the model.
*
* @param array|string $relations
* @param string $column
* @return $this
*/
public function loadMax($relations, $column)
{
return $this->loadAggregate($relations, $column, 'max');
}
/**
* Eager load relation min column values on the model.
*
* @param array|string $relations
* @param string $column
* @return $this
*/
public function loadMin($relations, $column)
{
return $this->loadAggregate($relations, $column, 'min');
}
/**
* Eager load relation's column summations on the model.
*
* @param array|string $relations
* @param string $column
* @return $this
*/
public function loadSum($relations, $column)
{
return $this->loadAggregate($relations, $column, 'sum');
}
/**
* Eager load relation average column values on the model.
*
* @param array|string $relations
* @param string $column
* @return $this
*/
public function loadAvg($relations, $column)
{
return $this->loadAggregate($relations, $column, 'avg');
}
/**
* Eager load related model existence values on the model.
*
* @param array|string $relations
* @return $this
*/
public function loadExists($relations)
{
return $this->loadAggregate($relations, '*', 'exists');
}
/**
* Eager load relationship column aggregation on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @param string $column
* @param string|null $function
* @return $this
*/
public function loadMorphAggregate($relation, $relations, $column, $function = null)
{
if (! $this->{$relation}) {
return $this;
}
$className = get_class($this->{$relation});
$this->{$relation}->loadAggregate($relations[$className] ?? [], $column, $function);
return $this;
}
/**
* Eager load relationship counts on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @return $this
*/
public function loadMorphCount($relation, $relations)
{
return $this->loadMorphAggregate($relation, $relations, '*', 'count');
}
/**
* Eager load relationship max column values on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @param string $column
* @return $this
*/
public function loadMorphMax($relation, $relations, $column)
{
return $this->loadMorphAggregate($relation, $relations, $column, 'max');
}
/**
* Eager load relationship min column values on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @param string $column
* @return $this
*/
public function loadMorphMin($relation, $relations, $column)
{
return $this->loadMorphAggregate($relation, $relations, $column, 'min');
}
/**
* Eager load relationship column summations on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @param string $column
* @return $this
*/
public function loadMorphSum($relation, $relations, $column)
{
return $this->loadMorphAggregate($relation, $relations, $column, 'sum');
}
/**
* Eager load relationship average column values on the polymorphic relation of a model.
*
* @param string $relation
* @param array $relations
* @param string $column
* @return $this
*/
public function loadMorphAvg($relation, $relations, $column)
{
return $this->loadMorphAggregate($relation, $relations, $column, 'avg');
}
/**
* Increment a column's value by a given amount.
*
* @param string $column
* @param float|int $amount
* @param array $extra
* @return int
*/
protected function increment($column, $amount = 1, array $extra = [])
{
return $this->incrementOrDecrement($column, $amount, $extra, 'increment');
}
/**
* Decrement a column's value by a given amount.
*
* @param string $column
* @param float|int $amount
* @param array $extra
* @return int
*/
protected function decrement($column, $amount = 1, array $extra = [])
{
return $this->incrementOrDecrement($column, $amount, $extra, 'decrement');
}
/**
* Run the increment or decrement method on the model.
*
* @param string $column
* @param float|int $amount
* @param array $extra
* @param string $method
* @return int
*/
protected function incrementOrDecrement($column, $amount, $extra, $method)
{
if (! $this->exists) {
return $this->newQueryWithoutRelationships()->{$method}($column, $amount, $extra);
}
$this->{$column} = $this->isClassDeviable($column)
? $this->deviateClassCastableAttribute($method, $column, $amount)
: $this->{$column} + ($method === 'increment' ? $amount : $amount * -1);
$this->forceFill($extra);
if ($this->fireModelEvent('updating') === false) {
return false;
}
if ($this->isClassDeviable($column)) {
$amount = (clone $this)->setAttribute($column, $amount)->getAttributeFromArray($column);
}
return tap($this->setKeysForSaveQuery($this->newQueryWithoutScopes())->{$method}($column, $amount, $extra), function () use ($column) {
$this->syncChanges();
$this->fireModelEvent('updated', false);
$this->syncOriginalAttribute($column);
});
}
/**