mlazuardy's avatar

file upload didnt update

i dont know where i did a mistake but right now my Avatar Profile can't be updated im forget to track the changes but here the controller

public function update(Request $request, $username)
    {
      $this->validate(request(), [
      'name'    =>'required|max:30',
      'username'    =>'required|max:30|alpha_dash|unique:users',
      ]);
        $user = $this->getUserByUsername($username);
        $input = Input::only('name', 'username');
        if ($request->hasFile('avatar')) {
            $request->file('avatar')->store('public/users/');

            $user->avatar = $request->file('avatar')->hashName('users/');
        }
        $user->fill($input)->save();
        $user->save();
        return redirect('profile/'.$user->username.'/account')->with('success', 'Profil Telah di Update');
    }

the username still work, but the name and avatar didnt update it, whats wroong?

0 likes
3 replies
Dunsti's avatar

are the fields you want to update (name and avatar) in the $fillable-array in your User-Model? Alternatively is $guarded set to an empty array?

Dunsti's avatar

you need to add all fields you want to save to the fillable-array. I often forget this, when I add new fields to the database-table. So it was just a guess, that maybe you also forgot it.

It doesn't matter, if you use fillable or guarded - the content of these matter. ;-)

Please or to participate in this conversation.