): array|array> */ protected array $states = []; public function __construct( protected string $connection ) { } public static function new(string $connection): static { return new static($connection); } /** * @param callable(array): array|array $state */ public function state(callable | array $state): static { $clone = clone $this; $clone->states[] = $state; return $clone; } /** * Génère le tableau de données avec les states et surcharges appliqués. * * @param array $attributes * @return array */ public function raw(array $attributes = []): array { $data = $this->definition(); foreach ($this->states as $state) { $stateData = is_callable($state) ? $state($data) : $state; $data = array_merge($data, $stateData); } return array_merge($data, $attributes); } /** * Insère un enregistrement dans la base Oracle répliquée et retourne le tableau inséré. * * @param array $attributes * @return array */ public function create(array $attributes = []): array { $data = $this->raw($attributes); $tableName = static::table()::name(); DB::connection($this->connection) ->table($tableName) ->insert($data); return $data; } /** * Insère N enregistrements dans la table. * * @param array $attributes * @return list> */ public function createMany(int $count, array $attributes = []): array { $rows = []; for ($i = 0; $i < $count; $i++) { $rows[] = $this->create($attributes); } return $rows; } }