php - I am getting MethodNotAllowedHttpException when uploading large excel sheet records to my database

111

I am trying to import data from excel file to my database , the problem is when i upload too many records i get this error message

MethodNotAllowedHttpException in RouteCollection.php line 219

Here is my code:

route.php

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

});

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 type="file" name="file"/>
            <button type="submit" >


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

Answer

Solution:

First of all,

Add theenctype to your form tag.

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

Then increase your post_max_size, upload_max_filesize in yourphp.ini if you're uploading files larger than specified inphp.ini

People are also looking for solutions to the problem: php - How to insert javascript var into path on Twig?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.