0

I am trying to add forgot password function in laravel, when i click reset password link it shows error "Undefined variable: title (View:". I have defined title in controller but still its showing this error. seems that passed data is not availabe in the view but its availble in forgot view.

my ResetPasswordController.php is

class ResetPasswordController extends Controller
{

    public function __construct()
    {

    }

    public function reset(Request $request) {
        $data['title'] = "Reset";

        return view('auth.passwords.reset',$data);
    }  

}

Forgot Password Works fine which has same @layout.app which has this 'title' variable, but Reset is not working. Following is code for route

Route::get('/password/forgot', [ 'as' => 'forgot', 'uses' => 'ForgotPasswordController@reset']);
Route::get('/password/reset', [ 'as' => 'reset', 'uses' => 'ResetPasswordController@reset']);

and view is

<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ $title }}</title>
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>
    <!-- Fonts -->
    <link rel="dns-prefetch" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">
    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light navbar-laravel">
            <div class="container"> 
                <a class="navbar-brand" href="{{ url('/') }}">
                    {{Config::get('constants.APP_TITLE')}}
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>


                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto"></ul>


                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        @guest
                            <li><a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a></li>
                            <li><a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a></li>
                        @else
                            <li><a class="nav-link" href="{{ route('users.index') }}">Manage Users</a></li>
                            <li><a class="nav-link" href="{{ route('roles.index') }}">Manage Role</a></li>
                            <li><a class="nav-link" href="{{ route('products.index') }}">Manage Product</a></li>
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>


                                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}
                                    </a>


                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>


        <main class="py-4">
            <div class="container">
            @yield('content')
            </div>
        </main>
    </div>
</body>
</html>

this working in forgot password view but gives error in reset password view

I have also tried

$title = "Reset";
    return view('auth.passwords.reset')->with('title', $title);
  • Before your question gets closed for the 2nd time, what is different between the ResetPassword Controller and the ForgotPasswordController. I would also mention, that you don't need to have 2 controllers. You could have a PasswordController and put both functions in there. – gview May 19 '20 at 03:37
  • difference is they have different view thats it. – vishal panchal May 19 '20 at 03:40
  • Then provide the full code for /auth/passwords/reset.blade.php – gview May 19 '20 at 03:42
  • I have added the code – vishal panchal May 19 '20 at 03:49
  • Have you tried `php artisan view:clear` – gview May 19 '20 at 03:50
  • i have manually cleared the view cache in storage/view – vishal panchal May 19 '20 at 03:52
  • try the things [suggested here](https://stackoverflow.com/questions/47904156/is-there-some-sort-of-laravel-controller-cache) one at a time – gview May 19 '20 at 03:57
  • is this problem with url because reset link is like https://exampple.com/password/reset/f1a7d550b78e7af05ed1c9fa303caf05b3c61c9b5eb5eb2d815af6d11809f?email=gmail.com but route is password/reset only and not with the token . how to add token to the route? – vishal panchal May 19 '20 at 04:02
  • That doesn't make sense. With that said, if you need a parameter to be passed, then in the route `Route::get('/password/reset/{token}` and your controller needs that parameter defined: `public function reset(Request $request, $token) ... – gview May 19 '20 at 04:16
  • tried php artisan view:clear it still not working – vishal panchal May 19 '20 at 06:33

2 Answers2

0

You have to use like this

return view('auth.passwords.reset',compact('data'));
A.A Noman
  • 5,244
  • 9
  • 24
  • 46
0

You can pass the variable into the view like answer by A.A.Noman or else you can do it like this.

return view('auth.passwords.reset',['data' => $data] );
Nipun Tharuksha
  • 2,496
  • 4
  • 17
  • 40