I believe in the case of REST API, the ViewModel would be a Laravel Resource wrapper:
classCreateUserJsonPresenterimplementsCreateUserOutputPort{publicfunctionuserCreated(CreateUserResponseModel$model):ViewModel{returnnewJsonResourceViewModel(newResources\UserCreatedResource($model->getUser()));}publicfunctionuserAlreadyExists(CreateUserResponseModel$model):ViewModel{returnnewJsonResourceViewModel(newResources\UserAlreadyExistsResource($model->getUser()));}publicfunctionunableToCreateUser(CreateUserResponseModel$model,\Throwable$e):ViewModel{if(config('app.debug')){// rethrow and let Laravel display the errorthrow$e;}returnnewJsonResourceViewModel(newResources\UnableToCreateUserResource($e));}}
I'll update the reference project with examples for a REST API and write another article about it. Stay tune!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I believe in the case of REST API, the ViewModel would be a Laravel Resource wrapper:
I'll update the reference project with examples for a REST API and write another article about it. Stay tune!