DataModel.php 701 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php declare(strict_types=1);
  2. namespace Inhere\ValidateTest\Example;
  3. use Inhere\Validate\ValidationTrait;
  4. /**
  5. * Class DataModel - custom extend the trait 'ValidationTrait' like the class 'Validation'
  6. */
  7. class DataModel
  8. {
  9. use ValidationTrait;
  10. protected array $data = [];
  11. // protected $db;
  12. /**
  13. * @param array $data
  14. *
  15. * @return $this
  16. */
  17. public function setData(array $data): self
  18. {
  19. $this->data = $data;
  20. return $this;
  21. }
  22. public function create(): bool|int
  23. {
  24. if ($this->validate()->isFail()) {
  25. return false;
  26. }
  27. // return $this->db->insert($this->getSafeData());
  28. return 1;
  29. }
  30. }