我正在尝试将数据从excel文件导入我的数据库,问题是当我上传太多记录时,我收到此错误消息
RouteCollection.php第219行中的MethodNotAllowedHttpException
这是我的代码:
route.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');
});
AdminController.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() !!}
答案 0 :(得分:0)
首先,
将enctype
添加到表单标记。
{!! Form::open(['files'=>true,'method'=>'post','url'=>'panel/uploadUsersExcel', 'enctype' => 'multipart/form-data']) !!}
如果您上传的文件大于php.ini