E
E
Eduard Bazhenov2019-10-24 22:40:19
Software design
Eduard Bazhenov, 2019-10-24 22:40:19

Where to implement such logic?

Hello. Got into application development to non-standard business logic. Here is a piece inserted into the controller:

public function update(Request $request, $id)
    {
        $part = RollPartsStorage::find($id);
        $part->lenght = $part->lenght - $request->lenght;
        $part->save();

        $roll_plus = new RollPartsStorage;
        $roll_plus->roll_storage_id = $request->roll_storage_id;
        $roll_plus->price = $request->price;
        $roll_plus->provider_id = $request->provider;
        $roll_plus->status_id = 1;
        $roll_plus->type_id = 2;
        $roll_plus->width = $part->width - $request->width;
        $roll_plus->lenght = $request->lenght;
        $roll_plus->save();

        $action = new RollActionsStorage;
        $action -> roll_storage_id = $request->roll_storage_id;
        $action -> type_id = 2;
        $action -> user_id = Auth::id();
        $action -> reason = $request->reason;
        $action -> width = $request->width;
        $action -> lenght = $request->lenght;
        $action->save();
        return redirect(route('roll.show', ['id' => $request->roll_storage_id]))->with(['part_status' => 'Изменения сохранены!', 'part_color' => 'success']);
    }

т.е. при списании куска ткани из рулона делается отрез, от него отрезается нужный кусок, сохраняется действие его списание, а остаток помещается в склад. При том, что такой функционал еще будет нужен при создании изделия.
Почитал и посмотрел много всего, о сервис-контейнерах и провайдерах, о сервисах, репозиториях.
Хотел сделать сервис-провайдеры для трех этих моделей, но не понимаю, нужен ли будет функционал провайдера, или можно сделать как-то проще и без излишевств. Подскажите, пожалуйста.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Wells, 2019-10-24
@kip_34

Вынеси логику куда захочешь.
В сервис, например.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question