Laravel 8 Does Not Update Information From Database

  laravel, laravel-8, php

I want to update my user information from database. I have this as form:

<form method="POST" action="{{ route('profile.update' , ['profile' => Auth::user()->id]) }}" class="form">
    <div class="form-group BSinaBold ">
        <input id="location" type="text" class="form-control" name="location" value="{{ Auth::user()->location }}" required autocomplete="location" autofocus>
    </div> 
</form>

And at the Controller, I put this in the method update:

public function update(Request $request, $profile)
    {
        $validate_data = Validator::make(request()->all(),[
           'location' => 'required'
        ])->validated();

        $user = User::findOrFail($profile);

        $user->update([
            'location' => $validate_data['location']
        ]);

        return back();
    }

But now the problem is, it does not update location. I mean there is no error appearing and no update at all!

So what’s going wrong here, how can I fix this?

I would really appreciate any idea or suggestion from you guys,

Thanks.

Source: Laravel

Leave a Reply