我正在尝试在我的laravel 5.4项目中使用excel包,这是在我上网的教程之后但是我一直收到这个错误
调用未定义的方法Illuminate \ Session \ Store :: getToken()(查看: C:\ wamp64 \ www \ Vidic \ resources \ views \ file_import_export.blade.php)in HtmlServiceProvider.php(第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()但是没有帮助。 我缩短了代码,使其易于理解
答案 0 :(得分:1)
这对我有用:将getToken()
更改为token()
答案 1 :(得分:-1)
1-在您的项目中,转到以下文件;
vendor \ laravelcollective \ html \ src \ HtmlServiceProvider.php
2-在 registerFormBuilder()方法/函数中,将 getToken()更改为 token()
我希望它也对您有用。
答案 2 :(得分:-3)
请尝试使用本教程。找到它Here