Search code examples
phplaravellaravel-5laravel-5.3

Laravel Update Route


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:


Solution

  • 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 }}" >