调用未定义的方法 Illuminate\Session\Store::getToken()

Call to undefined method Illuminate\Session\Store::getToken()

我正在尝试按照在线教程在我的 laravel 5.4 项目中使用 excel 包,但我一直收到此错误

Call to undefined method Illuminate\Session\Store::getToken() (View: C:\wamp64\www\Vidic\resources\views\file_import_export.blade.php) in HtmlServiceProvider.php (line 51)

这是我的 composer.json 文件

{
      "name": "laravel/laravel",
      "description": "The Laravel Framework.",
      "keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.6.4",
    "laravel/framework": "5.4.*",
    "laravel/tinker": "~1.0",
    "maatwebsite/excel": "~2.1.0",
    "illuminate/html": "5.*"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~5.7"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\": "app/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\": "tests/"
    }
},
"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\Foundation\ComposerScripts::postInstall",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "Illuminate\Foundation\ComposerScripts::postUpdate",
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist",
    "sort-packages": true,
    "optimize-autoloader": true
}
}

这是我的 app.php 文件

     'providers' => [
    /*
     * Laravel Framework Service Providers...
     */
    ...

    Illuminate\View\ViewServiceProvider::class,
    'Maatwebsite\Excel\ExcelServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',

    'aliases' => [
    ...
    'View' => Illuminate\Support\Facades\View::class,
    'Excel' => 'Maatwebsite\Excel\Facades\Excel',
    'Form' => 'Illuminate\Html\FormFacade',
    'HTML' => 'Illuminate\Html\HtmlFacade',
],
];

这是我的观点

            <body>
    <div class="panel panel-primary">
 <div class="panel-heading">Payments</div>
  <div class="panel-body"> 
  <div class="row">
      <div class="col-xs-12 col-sm-12 col-md-12">
        <a href="{{ route('excel-file',['type'=>'xls']) }}">Download Excel xls</a> |
        <a href="{{ route('excel-file',['type'=>'xlsx']) }}">Download Excel xlsx</a> |
        <a href="{{ route('excel-file',['type'=>'csv']) }}">Download CSV</a>
      </div>
   </div>     
       {!! Form::open(array('route' => 'import-csv-excel','method'=>'POST','files'=>'true')) !!}
        <div class="row">
           <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="form-group">
                    {!! Form::label('sample_file','Select File to Import:',['class'=>'col-md-3']) !!}
                    <div class="col-md-9">
                    {!! Form::file('sample_file', array('class' => 'form-control')) !!}
                    {!! $errors->first('sample_file', '<p class="alert alert-danger">:message</p>') !!}
                    </div>
                </div>
            </div>
            <div class="col-xs-12 col-sm-12 col-md-12 text-center">
            {!! Form::submit('Upload',['class'=>'btn btn-primary']) !!}
            </div>
        </div>
       {!! Form::close() !!}
 </div>
</div>

我已将 HtmServiceProvider.php 文件中的大部分方法(例如 bindShared())重命名为 singleton(),但这并没有帮助。 我已经缩短了代码以使其易于理解

尝试改用本教程。找到它 Here

这对我有用:将 getToken() 更改为 token()

Here is where I found my answer.

1 - 在您的项目中转到以下文件;

vendor\laravelcollective\html\src\HtmlServiceProvider.php

2-在registerFormBuilder()method/function中,将getToken()改为token()

我希望它也对你有用。