id = $id; $this->fetchRow(); } else { // если ID не задан, то мы генерируем ноывй $this->id = Cuid::cuid(); } } public function insert() { DB::table($this->tableName)->insert($this->getAttributes()); } public function update() { DB::table($this->tableName)->where('id', $this->id)->update($this->getAttributes()); } private function fetchRow() { $row = DB::where('id', $this->id)->first(); if (!$row) { throw new \UnableToCreateGatewayException(''); } } private function getAttributes() { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'password' => $this->password, ]; } } class User { private $gateway; public function __construct(UserGateway $gateway) { $this->gateway = $gateway; } public function save() { } }