Support the ongoing development of Laravel.io →
IOC Forms Architecture

I'm still trying to figure out where everything goes. So I have a customer page where we create/edit a customer. It pulls data from a lot of different tables i.e. customer table, pricing table, usually orders table, contacts table etc. All of those have there own repositories. Which I think is the way to design it, following single responsibility and the fact that that data needs to be accessed away from the customer sometimes.

Now when I save a customer where should I be doing that. Should I inject all those repositories into the controller and save from there. Should the customer repository take care of all the saving by being injected with all the needed repositories, something else I'm not thinking of?

EDIT: added code, it's off the top of my head so it might have errors but should illustrate.

I could do it in the controller:

class CustomerController{
    
    public function __construct(
                                   CustomerRepositoryInterface $customer,
                                   PricingRepositoryInterface $pricing,
                                  UsuallyOrdersRepositoryInterface $usuallyOrders
                                  4 or 5 more)
    {
        $this->customer = $customer;
        $this->pricing = $pricing
       etc...
    }

public function save($inputs){
    $id = $this->customer->save($inputs);
    $this->pricing->save($id, $inputs;
    $this->usuallyOrders($inputs, $id);
    etc...
}

Or I could do something similar in the Customer Repository and let that handle saving with all the models.

Last updated 2 years ago.
0

I think I know what you're looking for, but it would be much better if you post an example code to eliminate any miscommunication.

Last updated 2 years ago.
0

Guess it depends on your site, what defines a customer? If you have an ecommerce site, is someone that created an account? If so you wouldn't even need to create a customer, because all of your users are potential customers. The users table could have a one-to-many relationship with an orders table. Just one option. You could inject the order repository into your controller:

public function __construct(OrderRepositoryInterface $order)
{
    $this->order = $order;
}

public function store()
{
    $this->order->create(Auth::user()->id, Input::all());
}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2025 Laravel.io - All rights reserved.