jeudi 19 juillet 2018

Change variable data using different function in controller using Laravel

As you can see i declared a variable $tabname with an empty value in the function accountsettings(). Once the user submitted the form in my view file it will go to the function changepassword(). I am trying to change the value of the $tabname after the user submitted the form. My code does not seem to work. Any help would be appreciated. Thanks.

public function accountsettings()
    {
        $tabname = " ";
        return view('account_settings')->with("tabName", $tabname);
    }

 public function changepassword(Request $request, $id)
    {

        // $this->validate($request, [
        // 'newPassword' => 'required|confirmed|min:6',
        // ]);

        $user = Auth::user();

        $tabname = "password";

        $curPassword = $request->post('oldPassword');
        $newPassword = $request->post('newPassword');

        if (Hash::check($curPassword, $user->password)) {
            $user_id = $user->id;
            $obj_user = User::find($user_id)->first();
            $obj_user->password = Hash::make($newPassword);


        }
        else
        {

        }
           return redirect()->route('account_settings')->with("tabName", $tabname);

    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire