search

Home  >  Q&A  >  body text

How does Laravel display this error or success message?

The following is a controller for users to change passwords. I want to display the "success" or "failure" information of changing passwords in the view. How should I do this?

public function update(Requests\ResetPasswordRequest $request)
    {
        $id=\Auth::id();
        $user = User::findOrFail($id);
        $oldPassword=$request->input('oldPassword');

        if ($oldPassword==$user->password) {
            $user->update($request->input('password'));
            return redirect()->back(); //在视图中显示修改密码成功
        }else{
            return redirect()->back(); //在视图中显示修改密码失败
        }
    }
PHPzPHPz2797 days ago392

reply all(1)I'll reply

  • 某草草

    某草草2017-05-16 16:52:29

    Controller:

    return redirect()->back()->with('message', '修改密码成功')

    View:

    {{ $message }}

    reply
    0
  • Cancelreply