Comments (6)
I do still want to figure out the proper way to handle this situation, but I am now seeing that it should probably be handled within the command handler calling the repository.
from commander.
another option could be to have that logic in models (not every time i guess ;) )
in Post.php [model]
public static function createPost($postData, $image_ids)
{
$post = new static($postData);
$post->save();
foreach ($image_ids as $image_id) {
$post->images()->associate($image_id);
}
}
from commander.
All of this comes back to whether the code you need to add is an implementation detail or not. I like to break it down to "what is the end user actually trying to accomplish?" If the answer to that question is simply to publish a post, then I'd store the image attachment stuff within the handler.
from commander.
Also how to decide whether to do persistence by model ( eg.
$post->save();
or by repo.
$postRepo->savePost($post);
first option makes model aware of persistence implementation of framework, exception handling etc. which deviates from its purpose, also it would be handy to tackle persistence in handler if it is part of a transaction.
from commander.
I think it's a project decision. My way is always handle through repositories.
from commander.
Yep - that's just an architecture decision.
from commander.
Related Issues (20)
- Validation Decorator HOT 3
- Triggering executeDecorators before validateCommand (in ValidationCommandBus) HOT 1
- Laravel 5 HOT 2
- Method injection CommandHandler HOT 5
- Include a demo basic example project in repo HOT 1
- FIX mapInputToCommand accept $input null
- Testing CommandHandlers with PHPSpec?
- PHPSpec a CommandHandler with DispatchableTrait HOT 1
- CommanderTrait method getCommandBus detected as Controller action HOT 1
- Make mapInputToCommand optional in CommanderTrait HOT 7
- Returning created entity HOT 4
- Validation is being fired twice when using ValidationCommandBus
- Could the package allow for custom Mustache templates to be used when generating commands?
- Decorators of the parent command will be executed on the child command HOT 1
- Warning: Ambiguous class resolution HOT 1
- Specify properties types
- Could this be used in laravel 5 HOT 3
- Using CommanderTrait with Console commands
- Javascript Error on Lead deal analysis HOT 1
- Is this project maintained and usable in production? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commander.