diff --git a/README.md b/README.md index 26d3281..b9197f4 100644 --- a/README.md +++ b/README.md @@ -120,4 +120,10 @@ public function edit(string $type, int $id): View $viewModel = OrganizationViewModel::createEmpty(); return $viewModel->toView('organization.store'); +``` + +# 1.8 version add `fromDataObject` method + +```php +$viewModel = OrganizationViewModel::fromDataObject($orgData); ``` \ No newline at end of file diff --git a/composer.json b/composer.json index 527e378..d06985b 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name":"akbarali/view-model", - "version":"1.7", + "version":"1.8", "description":"View Model PHP Laravel", "license":"MIT", "minimum-stability": "stable", diff --git a/src/BaseViewModel.php b/src/BaseViewModel.php index 8041f85..a01be75 100644 --- a/src/BaseViewModel.php +++ b/src/BaseViewModel.php @@ -104,4 +104,9 @@ public static function createEmpty(): static { return new static(new EmptyData()); } + + public static function fromDataObject(DataObjectBase $data): static + { + return new static($data); + } }