use Infra\User\EloquentUserRepository; class RepositoryServiceProvider extends ServiceProvider { public function boot() { } public function register() { $this->app->bind(UserRepositoryInterface::class, EloquentUserRepository::class); } } Πϯελϯεͷొ
use Illuminate\Foundation\Auth\User as Authenticatable; class EloquentUserModel extends Authenticatable { public function toDomain(): User { return new User( new UserId($this->id), Name::of($this->first_name, $this->last_name) ); } } .PEFM
use Domain\User\UserRepositoryInterface; class EloquentUserRepository implements UserRepositoryInterface { public function get(UserId $id): User { $model = EloquentUserModel::where('id', $id->rawValue())->get(); return $model->toDomain(); } public function getList(): UserList { $collection = EloquentUserModel::all(); return new UserList($collection->map(function ($model) { return $model->toDomain(); })->toArray()); } } &MPRVFOU3FQPTJUPSZ*NQMFNFOU