Injection dependency in an update method from the router

Posted 2 years ago by ncrousset

Hello.

When I try to modify a record, eloquent creates a new record instead of modifying the instantiated.

public function editEmergencyContact(EmergencyContactRequest $request, EmergencyContact $emergencyContact)
{

    $application = Applications::findOrFail($request->application_id);

    if($application->Profile->user_id != Auth::id())
        return response()->json(['error' => 'Is not authorized to modify the registry'], 422);

    try {
        $input = $request->all();
        $input['updated_by'] = Auth::id();
        $input['updated_at'] = Carbon::now();

        $emergencyContact->fill($input);
        $emergencyContact->save();

    } catch (\Exception $e) {
        return response()->json(['error' => $e->getMessage() ], 400);
    }

    //if ($request->ajax()) return;


    dd($emergencyContact);

    return response()->json($emergencyContact, 201);


}

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

Reply to

Use Markdown with GitHub-flavored code blocks.