1
votes

Laravel newbie here, I want to create an update route in Laravel, without the resource controller. I have the route for the editing

Route::get('/indexedit','PagesController@indexedit')->middleware('user');

And in there, there is a form with the following

<form class="col s12" method="POST" action="indexedit/{{ $val->id }}" >
{{ method_field('PUT') }}
{{ csrf_field() }}

There are two input fields and a button for submiting. I created a route for the update which is

Route::post('indexedit/{$id}', 'PagesController@update');

But when I submit, it says Route not found. NotFoundHttpException in RouteCollection.php line 161:

2
Route::any('/indexedit/{id}', 'PagesController@update'); try it..Soniya Basireddy
Just tried, returns the same.Vedran Korponajić

2 Answers

3
votes

First of all you don't need $ sign in your route (Documentation):

Route::post('indexedit/{id}', 'PagesController@update');

Second of all, I would wrap action url in url() method just in case:

<form class="col s12" method="POST" action="{{ url('indexedit/ ' . $val->id }}" >
0
votes

You should use put from update rote, not post.

This not ok:

Route::post('indexedit/{id}', 'PagesController@update');

use this:

Route::put('indexedit/{id}', 'PagesController@update');