1
\$\begingroup\$

This is a controller, which receives the validated input from a http request, then finds the assorted model and for each translation key in the received data, it will add it to the model.

public function update(UpdateMenuItemRequest $request)
{
    $validated = $request->validated();

    $item = MenuItem::findOrFail($validated['id']);

    foreach($validated['translations'] as $validatedTranslation) {
        $item->translations()->updateOrCreate(['locale' => $validatedTranslation['locale']], $validatedTranslation);
    }

    return $item;
}

Is this Object Oriented enough? It doesn't seem like this method is violating SRP in the first place, or could it be improved? Thank you.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.