Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where and how to create a method to create items ? #2

Open
Cepairda opened this issue Jun 7, 2021 · 5 comments
Open

where and how to create a method to create items ? #2

Cepairda opened this issue Jun 7, 2021 · 5 comments

Comments

@Cepairda
Copy link

Cepairda commented Jun 7, 2021

I see a way to find items, but how can I create new items? How to do it right ?
Thanks

@shin1x1
Copy link
Owner

shin1x1 commented Jun 7, 2021

Hi, @Cepairda .
This repo does not have the feature of item creation. If you want to implement it, you would do the following.
(This is just one of many ideas.)

  • Add store method in ItemRepository.
    • Add store method in some classes which implements ItemRepository.
  • Add CreateItem in UseCases.
  • Add ItemController or CreateItemController in Controllers.
  • Add routing.

@Cepairda
Copy link
Author

Cepairda commented Jun 7, 2021

@shin1x1
Thanks! If I need to do creation in code somewhere, in a controller for example, is this a good solution?

$item = new Item(
ItemId::of($this->id),
$this->name,
ItemPrice::of($this->price),
Stock::of($this->stock)
);
$itemRepository->save($item);

@shin1x1
Copy link
Owner

shin1x1 commented Jun 8, 2021

Yes, it would be implemented that way.

@Cepairda
Copy link
Author

Cepairda commented Jun 8, 2021

@shin1x1
https://github.com/shin1x1/laravel-ddd-sample/blob/master/packages/Acme/Shop/Infrastructure/Eloquents/EloquentItem.php
Has a method - toDomain(), I will need to create a reverse method to load the entity into the model? Where to create it correctly ?

@Cepairda
Copy link
Author

@shin1x1
Hi, can you tell me how to correctly transform an entity into a eloquent model ? We have method toDomain, which converts the model to entity. To save the Entity, you need to convert Entity to a model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants