Laravel 我不能上传文件
我想导入和导出excel文件,以下是我的代码: 这是CustomerControllerLaravel 我不能上传文件,laravel,laravel-excel,Laravel,Laravel Excel,我想导入和导出excel文件,以下是我的代码: 这是CustomerController public function customersImport(Request $request) { if($request->hasFile('customers')) { $path = $request->file('customers')->getRealPath(); $data = \Excel::load($path)->ge
public function customersImport(Request $request)
{
if($request->hasFile('customers')) {
$path = $request->file('customers')->getRealPath();
$data = \Excel::load($path)->get();
if ($data->count()) {
dd($value);
foreach ($data as $key => $value) {
$customer_list[] = ['name' => $value->name, 'surname' => $value->surname, 'email' => $value->email];
}
if (!empty($customer_list)) {
Customer::insert($customer_list);
\Session::flash('Success', 'File imported succesfully');
}
}
}
else{
\Session::flash('warning','There is no file to import');
}
return Redirect::back();
}
这是我的客户
@extends('layouts.app')
@section('content')
<div class="panel-heading">Import and Export Data Into Excel File</div>
<div class="panel-body">
{!!Form::open(array('route'=>'customer.import','method'=>'POST','files'=>'true')) !!}
<div class="row">
<div class="col-xs-10 col-sm-10 col-md-10">
@if(Session::has('success'))
<div class="alert alert-success">
{{Session :: get('message')}}
</div>
@endif
@if(Session::has('warning'))
<div class="alert alert-warning">
{{Session::get('message')}}
</div>
@endif
<div class="form-group">
{!! Form::label('sample_file','Select File to Import:',
['class'=>'col-md-3']) !!}
<div class="col-md-9">
{!! Form::file('customers',array('class'=>'form-control')) !!}
{!! $errors->first('products','<p class="alert alert-danger">:message</p') !!}
</div>
</div>
</div>
<div class="col-xs-2 col-sm-2 col-md-2 text-center">
{!! Form::submit('Upload',['class'=>'btn btn-success']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
@endsection
当我点击上传文件时,错误显示:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
没有消息
你能帮我纠正一下吗?我不知道出了什么问题,屏幕上的错误消息也不清楚:您正在发布一条GET路线。查看有关不同HTTP谓词的更多信息
将路线更改为路线::post“customer-import”CustomerController@customersImport'->命名为'customer.import';应修复此错误。如何在路由文件中定义customer.import?路由::获取“customer-import”,“客户导入”CustomerController@customersImport'->命名为'customer.import';它说,;未定义变量:值这是一个完全不同的问题,但这是由于您的dd$值;语句,但尚未定义$value参数。但我想你所说的问题当时已经解决了: