lundi 24 juin 2019

Where is the best place to check a long logic in Laravel?

I have a long logic for checking if ordered products are compatible. and this logic is needed in two controllers. So I want to put this piece of code somewhere.

Is this a good idea to put this logic in OrderRepository while I want to follow Repository Pattern? if it's not, where is the best place?

here is the method for creating order in OrderRepository:

/**
 * Create the order
 *
 * @param array $params
 * @return Order
 * @throws OrderInvalidArgumentException
 */
public function createOrder(array $params) : Order
{
    try {
        $order = $this->create($params);

        $orderRepo = new OrderRepository($order);
        $orderRepo->buildOrderDetails(Cart::content());

        // Check the compatibility here

        event(new OrderCreateEvent($order));

        return $order;
    } catch (QueryException $e) {
        throw new OrderInvalidArgumentException($e->getMessage(), 500, $e);
    }
}

Aucun commentaire:

Enregistrer un commentaire