0

我正在尝试将数据从 excel 文件导入我的数据库,问题是当我上传太多记录时,我收到此错误消息

RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException

这是我的代码:

路由.php

Route::group(['prefix' => 'panel', 'middleware' => 'adminMiddleware'], function () {
    Route::get('/index', 'admin\AdminController@index');
    Route::post('/uploadUsersExcel', 'admin\AdminController@uploadUsersExcel');
    Route::post('/downloadUsersExcel', 'admin\AdminController@downloadUsersExcel');

});

管理员控制器.php

  public function uploadUsersExcel(Request $request)
    {


        if ($request->file('file')) {
            $name = 'uploads/csv/' . $request->file('file')->getClientOriginalName();
            $request->file('file')->move('uploads/csv/', $name);
            DB::table('users')->whereNotIn('id', [1])->delete();

            Excel::filter('chunk')->load($name)->chunk(250, function($reader)

            {

                $data = $reader->toArray();

                foreach ($data as $value) {
                    $user = new user();
                    $user->password = bcrypt($value['password']);
                    $user->save();
               }
            }

            );

        }

    }

users.blade.php

            {!! Form::open(['files'=>true,'method'=>'post','url'=>'panel/uploadUsersExcel']) !!}
                        <input class="form-control" type="file" name="file"/>
                        <button type="submit"  class="bigger-icon btn btn-block  btn-success">


upload
                        </button>
                        {!! Form::close() !!}
4

1 回答 1

0

首先,

添加enctype到您的表单标签。

 {!! Form::open(['files'=>true,'method'=>'post','url'=>'panel/uploadUsersExcel', 'enctype' => 'multipart/form-data']) !!}

然后增加你的post_max_sizeupload_max_filesize如果你php.ini上传的文件大于php.ini

于 2016-06-17T22:59:18.727 回答