hjortur17
254
11
General

Update avatar path

Posted 2 months ago by hjortur17

I'm trying to update my avatar path but my function won't​ enter the if statement

if (request()->filled('avatar_path'))
        {
            dd('avatar_path');

            request()->validate([
                'avatar' => ['image']
            ]);

            auth()->user()->update([
                'avatar_path' => request()->file('avatar')->store('avatars', 'public')
            ]);
        }

Here is my full update function:

    public function update(User $user)
    {
        $user->fill(request()->except('password', 'avatar_path'));

        if (request()->filled('password'))
        {
            request()->validate([
                'password' => 'confirmed'
            ]);

            $user->password = bcrypt(request()->input('password'));
        }

        if (request()->filled('avatar_path'))
        {
            dd('avatar_path');

            request()->validate([
                'avatar' => ['image']
            ]);

            auth()->user()->update([
                'avatar_path' => request()->file('avatar')->store('avatars', 'public')
            ]);
        }
        
        $user->save();

        return redirect()->route('profile', $user);
    }

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