更新用户个人资料Laravel

时间:2020-03-10 13:13:34

标签: php mysql laravel

我有问题,我无法更新用户个人资料,当我按“提交”时,我会得到一个过期的页面,我该如何解决?

我的表单:

<form method="post" class ="tab-pane" id ="edit" action="{{route('profile')}}">
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Email</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="email" value={{$user->email}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">About</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="text" value={{$user->about}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Skills</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="text" value={{$user->skills}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Hobbies</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="text" value={{$user->hobbies}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Address</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="text" value="" placeholder="Street">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label"></label>
                        <div class="col-lg-6">
                            <input class="form-control" type="text" value="" placeholder="City">
                        </div>
                        <div class="col-lg-3">
                            <input class="form-control" type="text" value="" placeholder="State">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Username</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="text" value={{$user->name}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label">Password</label>
                        <div class="col-lg-9">
                            <input class="form-control" type="password" value={{$user->password}}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-lg-3 col-form-label form-control-label"></label>
                        <div class="col-lg-9">
                            <input type="reset" class="btn btn-secondary" value="Cancel">
                            <<button type="submit">submit</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

我的路线:

Route::post('/profile', 'UserController@update_Profile');

还有我的UserController:

public function update_Profile(User $user) {

    $this->validate(request(), [
        'name' => 'required',
        'email' => 'required|email|unique:users',
    ]);

    $user->name = Request::input('name');
    $user->email = Request::input('email');

    $user->save();
    Flash::message('Your account has been updated!');
    return back();
}  

我通过主题尝试了不同的方法,但是失败了,您认为问题出在哪里?也许是因为我定义视图的方式还是因为路线?

1 个答案:

答案 0 :(得分:4)

exclude: "**/karma_junit.xml"放入您的表单。 像这样:

@CSRF

查看此:https://laravel.com/docs/5.8/csrf