webfuelcode
3 weeks ago
132
2
Laravel

How to make user personal records simple optional?

Posted 3 weeks ago by webfuelcode

I am using resource in route just to avoid messing up with route name whenever calling. So here I stuck in updating the user details. Trying to make it simple and optional entry.

public function update(Request $request, User $user)
    {
        $this->validate(request(), [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required|min:6|confirmed'
        ]);

        $user->name = request('name');
        $user->email = request('email');
        $user->password = bcrypt(request('password'));

        $user->save();
        return redirect()->back()->withMessage('Your personal data is successfully edited!');
    }

Suppose I want to let the member just change the password. Do I need to get a separate view page and a separate controller function?

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