Htmlspecialchar.php 696 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Casts;
  3. use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Htmlspecialchar implements CastsAttributes
  6. {
  7. /**
  8. * Cast the given value.
  9. *
  10. * @param array<string, mixed> $attributes
  11. */
  12. public function get(Model $model, string $key, mixed $value, array $attributes): mixed
  13. {
  14. return htmlspecialchars_decode($value);
  15. }
  16. /**
  17. * Prepare the given value for storage.
  18. *
  19. * @param array<string, mixed> $attributes
  20. */
  21. public function set(Model $model, string $key, mixed $value, array $attributes): mixed
  22. {
  23. return htmlspecialchars($value);
  24. }
  25. }