Coder Social home page Coder Social logo

Related Models about commander HOT 6 CLOSED

laracasts avatar laracasts commented on July 27, 2024
Related Models

from commander.

Comments (6)

ajschmaltz avatar ajschmaltz commented on July 27, 2024

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.

hardevine avatar hardevine commented on July 27, 2024

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.

 avatar commented on July 27, 2024

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.

hardevine avatar hardevine commented on July 27, 2024

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.

bruno-barros avatar bruno-barros commented on July 27, 2024

I think it's a project decision. My way is always handle through repositories.

from commander.

 avatar commented on July 27, 2024

Yep - that's just an architecture decision.

from commander.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.