andrethedev

andrethedev

Member Since 1 Month Ago

Experience Points
80
Total
Experience

4,920 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
80 XP
Dec
10
1 month ago
Activity icon

Replied to Where Are You All From?

Rio de Janeiro, Brazil :D

Dec
04
1 month ago
Activity icon

Replied to Help With Pattern For Project

Thanks for the advices, @goldtaste .

About the foreach... inside it there is more than one service related to the members. Should I have pass the list and have the same loop on both services? Something like this:

... some code ...
$this->addMemberToContract->execute(id, $data['member_list'])

$this->addMembershipCardToMember->execute(id, $data['member_list'])
... some code ...

And then I make the loop on the services? Wouldn't that be redundant? Or its ok to do that in this scenario?

About the services, I'm trying to make them more loose. Maybe have a class 'CreateContractManager' (or some better name?) that will be called for the controller. And then this manager will call all the services necessary for his execution. The services would just make one action without worry about anything. The worry for the execution flux would be on the manager class hands.

Do this make sense? Am I separating the business logic too much? I tried to search for patterns like this but found nothing...

Activity icon

Replied to Help With Pattern For Project

Thanks for the tips, @bugsysha

I didn't know about this 'responsable', so I will study about it and how apply it on my case.

About the change on the __construct(), what are the benefits of the change?

Dec
03
1 month ago
Activity icon

Started a new Conversation Help With Pattern For Project

I'm trying to figure it out the best approach to develop a project that I'm working on (and that have the possibility of growing). Maybe you guys can give some advice, some tips.

On the application, there will be a section to create a contract. At the same time, the app should insert the members of contract, membership cards for each member, a sale (with price) of the contract, a sale comission for the seller, a group of monthly payments. All of this coming from one single form.

I was thinking on let the controllers on the clean side, dividing responsabilities with others layers. The idea until now is explained with some sample codes:

[ContractController.php]

use App\Http\Requests\CreateContractRequest;
use App\Services\CreateContractService;

class ContractController {

    public function create(CreateContractRequest $request, CreateContractService $service) {
    
        $contract = $service->execute($request->only(
            'cod_plan', 
            'cod_seller',
            'expiration_date',
            'member_list',
            ... other columns ...
        ));
        
        return response()->json($contract, 201);
    
    }
    
}

[CreateContractService.php]


use App\Repositories\ContractRepository;

use App\Services\AddMemberToContractService;
use App\Services\AddMembershipCardToMemberService;
use App\Services\CreateSaleService;

class CreateContractService {

    public function __construct() {
        
        $this->contractRepo = new ContractRepository();
        
        $this->addMemberToContract = new AddMemberToContractService();
        $this->addMembershipCardToMember = new AddMembershipCardToMemberService();
        $this->createSale = new CreateSaleService();
    
    }
    
    public function execute(array $data) {
        
        // Create contract
        $new_contract = $this->contractRepo->create($data);
        
        foreach ($data['member_list'] as $m) :
            
            // Add members
            $new_member = $this->addMemberToContract->execute($id_contract, $m);
            
            // Create membership cards for members
            $new_card = $this->addMembershipCardToMember->execute($new_member);
        
        endforeach;
        
        // Create sale
        $new_sale = $this->createSale->execute($data);
        
        ... others inserts ...
        
        return $new_contract;
            
    }

}

[ContractRepository.php]


use App\models\Contracts;

class ContractRepository {

    public function create(array $data) {
    
        $o_contract = new Contracts();
        $o_contract->cod_plan = $data['cod_plan'];
        $o_contract->cod_seller = $data['cod_seller'];
        
        ... other columns ...
        
        $o_contract->save();
        
        return $o_contract;
    
    }

}

With that, I have some questions.

  1. This approach make sense? Is the better way of do it? I'm trying to make the code more reusable and decoupled.

  2. Can I (and should I) separate more the services and the logic behind them?

  3. How should I handle the errors? Use exceptions? Even for ajax requests? Should I verify for errors on each part of the 'execute' method and return messages mannually?

  4. If I have to work with exceptions, how can make my own exceptions?

  5. If some part of the code result on a error, how can I undo the inserts already done to make sure that the user can utilize the form to try the same insertion again?

  6. On the services, should I only return data objects, booleans or responses?

  7. The responses are better just in the controllers?

  8. How should I handle errors on the repositories and pass the same errors to the services?

  9. With this structure, can I make tests more easily?

  10. Its hard to use the same code to a web and a api version of the app?

I appreciate the help.

(Sorry if the english is not that good...)