rameezisrar's avatar

MethodNotAllowedHttpException on file upload

Well, I was successfully able to upload a file on my local server. When I switch to the Production Server, I am unable to upload a file and I get this MethodNotAllowedHttpException error.

Also, I am forcing https loads

AppServiceProvider.php

  public function boot()
    {
       
        if (App::environment('production', 'staging'))
        {
            URL::forceScheme('https');
        }   
    }

Here is the blade.php file

<form role="form" method="POST" action="update" enctype="multipart/form-data"> 
                @csrf
                    <div class="box-body">
                        <div class="form-group">
                            <label for="exampleInputPassword1">Type</label>
                            <select class="form-control select2" style="width: 100%;" name="product_id">
                                 @foreach($products as $product)
                                    <option value="{{$product->id}}" @if("{{$product->id}}" === "{{$ProductWorkoutCategory->product_id}}") selected="selected" @endif >{{$product->name}}</option>
                                @endforeach   
                             </select>
                        </div>
                        <div class="form-group">
                            <label for="exampleInputPassword1">Type</label>
                            <select class="form-control select2" style="width: 100%;" name="workout_category_id">
                                 @foreach($workout_categories as $category)
                                    <option value="{{$category->id}}" @if("{{$category->id}}" === "{{$ProductWorkoutCategory->workout_category_id}}") selected="selected" @endif >{{$category->title}}</option>
                                @endforeach   
                             </select>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button type="submit" class="btn btn-primary">Submit</button>
                    </div>
                </form>

and here is the controller function that update the file and data

        $product = Product::find($id);
            $product->name = $request->name;
            $product->type = $request->type;
            $product->category = $request->category;
            $product->plan_id = $request->plan_id;
            $product->price = $request->price;
            $product->picture = $request->file('picture')->store('products','public');
            $product->save();
0 likes
3 replies
AlexDemin's avatar

MethodNotAllowedHttpException is usually about your routes file...

1 like
AlexDemin's avatar
  • run: "php artisan route:list" preferably on your production server.
  • indicate the route (POST method) that corresponds to this form.
  • set that named route as your form action:
<form role="form" method="POST" action="{{ route('name.of.your.route') }}" enctype="multipart/form-data"> 
1 like
rameezisrar's avatar

@AlexDemin Thankyou for the reply but actually there is no such error on my local server. I am forcing https on my Production. @Cronix what do you think?

Please or to participate in this conversation.