我正在尝试将数据从 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() !!}