0

i am trying to edit default Auth user in laravel and i get the error when i submit my edit form so here is my controller :

class UserController extends Controller
{

public function __construct()

{
    $this->middleware('auth');
}

public function edit(User $user)
{
    $user = Auth::user();
    return view('admin.profile.edit', compact('user'));
}

public function update(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 back();
}
}

and here is my view file when of form i just put the form here

    <form method="post" action="{{route('users.edit', $user)}}">
                    {{ csrf_field() }}
                    {{ method_field('patch') }}
                    <input type="text" name="name"  value="{{ $user->name }}" />

                    <input type="email" name="email"  value="{{ $user->email }}" />

                    <input type="password" name="password" />

                    <input type="password" name="password_confirmation" />

                    <button type="submit">Send</button>
                </form>

so the important file which i 90% sure that the problem is with is my route i know that i am some how sending some get to post or vise i am really confused with this part

Route::get('admin/profile/{user}',  ['as' => 'users.edit', 'uses' => 'UserController@edit']);
Route::post('admin/profile/{user}/update',  ['as' => 'users.update', 'uses' => 'UserController@update']);

so now when i submit the form i get this error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

and btw i have tried to use patch route with hidden input too but yet again same out put .

1 Answer 1

2

ok So found the problem i have to change the user edit route to user update so

<form method="post" action="{{route('users.edit', $user)}}">

would be changed to this

<form method="post" action="{{route('users.update', $user)}}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.