Search code examples
phplaravellaravel-5.3

Whoops, looks like something went wrong. LARAVEL ERROR


I wanted to make a basic login/logout in Laravel. So I created a new folder under resources/views called auth and then I made a new file login.blade.php inserted this into it:

   <html>
<body>
<form>
<input type="text" name="email" placeholder="email" size="40"><br><br>
<input type="password" name="password" placeholder="password" size="40"><br><br>
<input hidden name="_token" value="{{csrf_token}}">
<input type="submit" value="send"> 
</form>
</body>
</html>

After that I edited the web.php like this:

    Route::get('/', function () {
    return view('welcome'); });

Route::get('/home', function () {
    return view('welcome'); });

Route::get('/login', function () {
    return view('auth.login'); });

Route::post('/login','Auth\LoginController@login');

Route::post('/logout','Auth\LoginController@logout');

So it should work fine because everything makes sense but whenever I goto login url, I see this error message:

ErrorException in 6c95db2d362954448afd30aa9a2bf2cb0fc31937.php line 6: Use of undefined constant csrf_token - assumed 'csrf_token' (View: G:\xampp\htdocs\o2architect\root\laravel\resources\views\auth\login.blade.php)

So can anyone tell me whats going on here ?!


Solution

  • Change it:

    <input hidden name="_token" value="{{csrf_token}}">
    

    to

    <input hidden name="_token" value="{{ csrf_token() }}">
    

    and try again.