9 months ago

updateOrCreate need more help cleaning code

Posted 9 months ago by chrisgrim

Hi, I just asked a question about cleaning code but I was too premature with my best answer. I am using a updateOrCreate and so I need to write my code this like

public function store(OrganizerStoreRequest $request, Event $event, Organizer $organizer)
        if (!$organizer = $organizer->updateOrCreate(
                    'slug' => str_slug(request('title'))
                    $request->all() + ['user_id' => auth()->id()]
            )) {
            return response()->json(['error' => 'Failed to save organizer'], 402);

This doesn't work because of this part I'm sure

$request->all() + ['user_id' => auth()->id()]

but is there a way to write this without listing all of the requests? Thanks!

Please sign in or create an account to participate in this conversation.