Support the ongoing development of Laravel.io →
Requests Architecture Eloquent
Last updated 2 years ago.
0

Without looking too much into the code (the general idea looks fine. and if you want only the evaluation of the algorithm then excuse my comments :P), I could only say that the method is directly dependent on two Models: Keyword and KeywordPlan. So, maybe thats too much responsibilities.

Besides, I guess you could benefit from some kind of Repositories for managing your models (unless your doing very simple CRUDs among entities that dont relate with each other, I always find it a good idea to abstract Model management). In fact, in cases where you have Models, or Entities, working closely together (like aggregates), sometimes its a good idea to abstract that one away, in a "Job", or in other languages they use "gateways".

Lastly, one could argue again hat the method has too many responsibilities. (remember SOLID principles). I might be wrong on that one cause im slow on catching those kiind of thiings and could've done with reviewing your code more, but, for example:

    // Get rid of old relationsihp with current keywords plan.
    $current_keywords->detach($original_keyword);

    // if the original keyword has no other relation, delete it.
    $original_keyword->deleteLast();

There you are talking about the logic for when the keyword has been added, so maybe that "step" could be on its method and if later you decide to change what is to be done when you add a keyword, well, everything else works perfectly.

But maybe, depending on how simple the app is, you dont need any of that.

Well, thats my 2 cents. Just wanted to participate :)

0

Igalaz,

thank you vere much for your observation, I appreciate it a lot. The app so far is pretty simple, but sounds like a good Idea to look into (Abstract Model management) and Laravel Jobs.

Again thank you very much for your time, it's greatly appreciated.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Itachicz11 itachicz11 Joined 12 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.