2
votes

I am getting a 404 status code on a laravel resource route when posting a model bound form. The form opening tag is as follows:

{!!Form::model($project, ['route' => ['admin.projects.update', $project->id], 'method' => 'PUT', 'files' => true])!!}
//Form content here
{!! Form::close() !!}

And the resource route as it appears under routes:list is:

+--------+----------+-----------------------------------+-------------------------+------------------------------------------------------------------+------------+
| Domain | Method   | URI                               | Name                    | Action                                                           | Middleware |
+--------+----------+-----------------------------------+-------------------------+------------------------------------------------------------------+------------+
|        | PUT      | admin/projects/{projects}         | admin.projects.update   | App\Http\Controllers\Admin\AdminProjectsController@update        |            |

and the controller:

public function update(CreateProjectRequest $request, $id)
{
  $data = $request->all();
  $project = Project::findOrFail($id);
  $project->update($data);
  return redirect('admin/projects/edit/all');
}

When I check the response in devtools, the payload is attached and the route url is correct. For example, if I am updating a project with an id of 150, the url is

http://localhost:8888/project-name/public/admin/projects/150

If I don't make any changes, the redirect from the controller works. If I only add files through the form it also works. It's when I change the text input data that I have the issue. I've never had this issue using resourceful routing before and can't for the life of me solve the issue after a couple of hours of trying.

Any fresh eyes see where I am making a mistake?

1
What's your update method? Does it redirect to somewhere else if the text value is present?James
The method is PUT (automatically spoofed by Laravel). There are no other redirects. The inputs have their existing values by default.Bill Dukelow
Do you have any validation that could redirect to an error page when you have an incorrect input?Needpoule
I do, but the redirect is back to the edit page with the $errors array. This doesn't redirect at all. The 404 is on the route url and doesn't redirect unless no changes are made or I add files to the file input (*not shown in the controller example for the purposes of brevity). This is what has me puzzled. If the route is run successfully on a file input then it should run on a text input change too. The fact that it throws a 404 on one and not the other makes no sense. The route is either found or its not.Bill Dukelow

1 Answers

0
votes

ANSWER

Tiredness induced sloppy code. I made the same call twice to a method that brought in the original record data and was used later to reference the record being updated.