Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CSRF令牌不匹配,laravel和axios_Php_Reactjs_Laravel_Axios - Fatal编程技术网

Php CSRF令牌不匹配,laravel和axios

Php CSRF令牌不匹配,laravel和axios,php,reactjs,laravel,axios,Php,Reactjs,Laravel,Axios,我正在尝试为用户登录,但当我尝试登录时,出现错误状态代码419。CSRF令牌不匹配。 我正在使用php artisan serve在上运行localhost 我想问题是我使用的是http而不是https,但我不确定(因为我知道php artisan Service只在http上工作) api.js Route::group(['middleware' => ['web']], function () { Route::post('register','Auth\RegisterContro

我正在尝试为用户登录,但当我尝试登录时,出现错误
状态代码419。CSRF令牌不匹配。

我正在使用
php artisan serve
在上运行localhost

我想问题是我使用的是http而不是https,但我不确定(因为我知道php artisan Service只在http上工作)

api.js

Route::group(['middleware' => ['web']], function () {
Route::post('register','Auth\RegisterController@register');  
Route::post('login','Auth\LoginController@login');  

});
登录控制器

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Auth;
use Illuminate\Http\Request;
class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    //protected $redirectTo = RouteServiceProvider::HOME;
    protected $redirectTo =  '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {

        $this->middleware('guest')->except('logout');
    }
}
有人知道如何纠正这个问题吗

谢谢你

我能帮你
onSubmit(e){
        e.preventDefault();
        const {email , password} = this.state ;
        axios.post('api/login', {
            email, 
            password
          })
          .then(response=> {
            this.setState({err: false,loggedIn:true,data:response.data.credentials.email},() => {
                localStorage.setItem('allProjects', this.state.data), localStorage.setItem('loginVar', JSON.stringify(true))});
             hashHistory.push("/") ; 

          })
          .catch(error=> {
            this.refs.email.value="";
            this.refs.password.value="";
            this.setState({err: true,loggedIn:false, errors: error.response.data,data:''});
            console.log(error.response.data);
            localStorage.setItem('allProjects', 'guest');
            localStorage.setItem('loginVar', false);


         });
     }