A PHP Controller, which feels to 'array-like', in Laravel
You could use route model binding to remove some lines from your code, but that would require changing the route so it passes the MenuItem's id.


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

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

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

    return $item;
}


Also, if you want legibility and go all out with functional programming, you could replace your loop with a collection method.

# Assuming the request object only has a translation array since you don't need the id anymore
public function update(MenuItem $item, UpdateMenuItemRequest $request)
{
    collect($request-&gt;validated()['translations'])-&gt;each(function ($translation) use ($item) {
        $item-&gt;translations()-&gt;updateOrCreate($translation);
    });
}


Depending on what kind of relationship we're dealing with there could be other ways as well.