0

I am getting the MethodNotAllowedException error whenever I try to submit a PATCH request to my controller. It only occurs on my nested route, all other routes that run the PATCH request work great.

routes.php:

Route::resource('customers.aircraft','AircraftController');

my form:

Form::model($aircraft, ['method' => 'PATCH', 'class' => 'form-horizontal', 'action' => ['AircraftController@update', $aircraft->id]])

Each aircraft belongs to a customer. My URL looks like this:

example.com/customers/5/aircraft/6/edit

What I'm observing in the address bar when I get the error message is this:

example.com/customers/6/aircraft

I have determined that this cannot be caused by the controller, because the very first line in my @update method is dd($request); and it doesn't get that far. I assume the issue is that the route is not getting the information it needs to direct my request, it is obviously taking the aircraft_id and using it as the customer_id, but I cannot figure out how or why.

I have tried this:

Form::model($aircraft, ['method' => 'PATCH', 'class' => 'form-horizontal', 'action' => ['AircraftController@update', [$customer_id, $aircraft->id]]])

Thinking that it needed the customer_id to be sent through, but that didn't work. I'm pretty new to Laravel so I do expect this is just a lack of knowledge, however nothing on Stackoverflow, Laravel or Laracasts websites have helped me so far.

Andrew Fox
  • 794
  • 4
  • 13
  • 30

1 Answers1

0

Try to use Put() method :

Form::model($aircraft, ['method' => 'PUT', 'class' => 'form-horizontal', 'action' => ['AircraftController@update', $aircraft->id]])

for Route::resource, the update method url should be like this :

example.com/aircraft/6

public function update(AircraftRequest $request, $aircraft_id) 
{ 
   $data = $request->all();
   dd($data['registration']); 
   $request['registration'] = strtoupper($request['registration']); 
   $aircraft->findOrFail($aircraft_id)->update($request->all());
   return redirect()->action('AircraftController@show', $aircraft_id); 
 }

so try to send customer_id in hidden input. Let me know if it works

BKF
  • 1,298
  • 4
  • 16
  • 35
  • still getting the same result – Andrew Fox Apr 16 '16 at 19:43
  • Could you show me your AircraftController@update method – BKF Apr 16 '16 at 19:48
  • public function update(AircraftRequest $request, Aircraft $aircraft, $customer_id, $aircraft_id) { dd($request); $request['registration'] = strtoupper($request['registration']); $aircraft->findOrFail($aircraft_id)->update($request->all()); return redirect()->action('AircraftController@show', $aircraft_id); } – Andrew Fox Apr 16 '16 at 19:49
  • I've only just added the $customer_id for troubleshooting and I've also tried without the AircraftRequest – Andrew Fox Apr 16 '16 at 19:49
  • Ok try again and tell me if it returns data – BKF Apr 16 '16 at 19:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109341/discussion-between-andrew-fox-and-bkf). – Andrew Fox Apr 16 '16 at 19:55