4 months ago

How to optimize my controller ?

Posted 4 months ago by unixlab

Hi there I've 3 controllers: ProfileEmailController , ProfileNameController and ProfilePasswordController

in each of them i have a simple method called update() with the only purpose of updating the corresponding information

Here's an example

    public function update(Request $request)
        if (Validator::make($request->all(), [
            'email' => 'required|email'
        ])->fails()) {
            return response()->json(['success' => false, 'message' => 'Please type correct email address']);
        $user = User::find(Auth::id());
        $user->email = $request->email;
        return response()->json(['success' => true, 'message' => 'Your email address was updated successfully']);

Is there any other way of doing this without repeating myself in all 3 controllers ?

Thanks in advance

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