0
votes

any expert here ? This is a very strange problem I am facing.

I have my website hosted on an aws machine. The code was working absolutely fine there. Then it was shifted to another server and this strange problem staeted to appear.

I have a route to update a car

Route::put('vehicles/{vehicle}', 'VehicleController@update');

Edit form

{!! Form::model($vehicle, ['url' => ['backend/vehicles', $vehicle->id], 'method' => 'put','files' => true , 'class' => 'form-horizontal form-label-left', 'role' => 'form']) !!}

   @include( 'backend.vehicles.form' )

{!! Form::close() !!}

Now here is where the strange behaviour start, whenever I try to update a car which was created prior to the server move, It shows me MethodNotAllowedHttpException in RouteCollection.php

But when I create a car and then updates this new car, Operation succeeds. Please help.

One more thing, In routeCollection.php where it matches a route for a request, It shows GET method for old car but put method for new car

public function match(Request $request){
   // die($request->getMethod()); $routes = $this->get($request->getMethod());
   $route = $this->check($routes, $request);

    if (! is_null($route)) {
        return $route->bind($request);
    }

    // If no route was found we will now check if a matching route is specified by
    // another HTTP verb. If it is we will need to throw a MethodNotAllowed and
    // inform the user agent of which HTTP verb it should use for this route.
    $others = $this->checkForAlternateVerbs($request);

    if (count($others) > 0) {
        return $this->getRouteForMethods($request, $others);
    }

    throw new NotFoundHttpException;
}

Please anyone.

2

2 Answers

0
votes

Add this inside the form

{{ method_field('PUT') }}

or in HTML

<input type="hidden" name="_method" value="PUT">
0
votes

Please try the following solution:

Route::put('vehicles/{vehicle}', 'VehicleController@update');

Change to

Route::match(['put', 'patch'], 'vehicles/{vehicle}', 'VehicleController@update');

And the form to

{!! Form::model($vehicle, ['action' => ['VehicleController@update', $vehicle->id], 'method' => 'put','files' => true , 'class' => 'form-horizontal form-label-left', 'role' => 'form']) !!}

   @include( 'backend.vehicles.form' )

{!! Form::close() !!}

Does it work for you?