Laravel 5.5 login and register page says:The page has expired due to inactivity.[TokenMismatchException]

后端 未结 17 3193
你的背包
你的背包 2020-12-09 05:11

I just created a new project of laravel version 5.5 with the laravel installer.And run the command \"php artisan make:auth\".The views and controller are generated

相关标签:
17条回答
  • 2020-12-09 06:03

    Sorry for Answering later I had same problem after searching on the internet found two solutions

    1-Add

    @csrf
    

    or

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

    inside your form if missing

    2:if you opened you login page for long time and didn't logged in. just refresh the browser or press ctrl+F5

    0 讨论(0)
  • 2020-12-09 06:04

    Add csrf token

           <input type="hidden" name="_token" value="{{ csrf_token() }}">
    
    0 讨论(0)
  • 2020-12-09 06:09

    try this one in your global handler app/Exceptions/Handler.php

    public function render($request, Exception $e)
    {
        if ($e instanceof \Illuminate\Session\TokenMismatchException) {
    
            return redirect('/login');
    
        }
    
        return parent::render($request, $e);
    }
    
    0 讨论(0)
  • 2020-12-09 06:09

    Make sure your User.php model exist in app folder and fields must be define in this model.

    <?php
    
    namespace App;
    
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
    class User extends Authenticatable
    {
        use Notifiable;
    
        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'name', 'email', 'password',
        ];
    
        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden = [
            'password', 'remember_token',
        ];
    }
    
    0 讨论(0)
  • 2020-12-09 06:15

    Hi for the group paths that you want to apply to everyone, use this method, which is my 5.5 larval version. Use the star => go to app/Http/Middleware/VerifyCsrfToken and add

    protected $except = [
        '/user/*'
    ];
    

    This is also my user's path

    Route::group(['prefix' => 'user', 'namespace' => 'User', 'as' => 'user.'] , function (){
    
    0 讨论(0)
提交回复
热议问题