Commit d3e9177
committed
Prevent Attribute accessors from running for non-arrayable attributes
Ensure that Attribute-based accessors are only invoked for arrayable
attributes during model serialization. This prevents hidden / non-visible
attributes from triggering accessors as a side-effect of toArray() /
toJson(), which can cause unnecessary work or unexpected exceptions.
- Derive mutated attributes only from arrayable keys via
getArrayableMutatedAttributes().
- Lazily resolve Attribute accessors in hasAttributeGetMutator() and
cache the result per class/key.
- Avoid invoking Attribute methods in getAttributeMarkedMutatorMethods();
inspect return types only.
- Use the new Attribute-based mutator path consistently in
mutateAttributeForArray().
Includes tests covering:
- non-visible Attribute accessors not being called
- visible Attribute accessors being called
- hidden Attribute accessors not being called
- set-only Attribute mutators not breaking serialization1 parent 40506d8 commit d3e9177
File tree
2 files changed
+161
-25
lines changed- src/Illuminate/Database/Eloquent/Concerns
- tests/Database
2 files changed
+161
-25
lines changedLines changed: 52 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
224 | 227 | | |
225 | | - | |
| 228 | + | |
226 | 229 | | |
227 | 230 | | |
228 | 231 | | |
| |||
679 | 682 | | |
680 | 683 | | |
681 | 684 | | |
682 | | - | |
683 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
684 | 689 | | |
685 | 690 | | |
| 691 | + | |
686 | 692 | | |
687 | | - | |
| 693 | + | |
688 | 694 | | |
689 | 695 | | |
690 | | - | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
691 | 703 | | |
692 | 704 | | |
693 | 705 | | |
| |||
752 | 764 | | |
753 | 765 | | |
754 | 766 | | |
755 | | - | |
756 | | - | |
| 767 | + | |
| 768 | + | |
757 | 769 | | |
758 | 770 | | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
763 | 775 | | |
764 | 776 | | |
765 | 777 | | |
| |||
2437 | 2449 | | |
2438 | 2450 | | |
2439 | 2451 | | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
2440 | 2466 | | |
2441 | 2467 | | |
2442 | 2468 | | |
| |||
2449 | 2475 | | |
2450 | 2476 | | |
2451 | 2477 | | |
2452 | | - | |
2453 | | - | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
2454 | 2489 | | |
2455 | 2490 | | |
2456 | 2491 | | |
| |||
2482 | 2517 | | |
2483 | 2518 | | |
2484 | 2519 | | |
2485 | | - | |
2486 | | - | |
2487 | | - | |
2488 | | - | |
2489 | | - | |
2490 | | - | |
2491 | | - | |
2492 | | - | |
2493 | | - | |
2494 | | - | |
2495 | | - | |
2496 | | - | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2497 | 2524 | | |
2498 | 2525 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3546 | 3546 | | |
3547 | 3547 | | |
3548 | 3548 | | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
| 3641 | + | |
| 3642 | + | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
| 3647 | + | |
| 3648 | + | |
| 3649 | + | |
| 3650 | + | |
| 3651 | + | |
| 3652 | + | |
| 3653 | + | |
| 3654 | + | |
| 3655 | + | |
| 3656 | + | |
| 3657 | + | |
3549 | 3658 | | |
3550 | 3659 | | |
3551 | 3660 | | |
| |||
0 commit comments