I am trying to send {slug} in route:
Route::post('page-edit/{slug}', 'PageController@postSavePage');
in view I have:
{!! Form::open(array('action' => 'PageController@postSavePage')) !!}
in controller:
public function postSavePage($slug = null){
dd($slug);
}
but I have error:
Missing required parameters for [Route: ] [URI: page-edit/{slug}]. (View: /var/www/html/CMS/resources/views/admin/pages/page-edit.blade.php)
What is the correct syntax?
If you want the slug to be optional, you have to add a question mark (?) to the parameter name in the
routes.php
file.Like so:
If you do not do this, you have to add the slug to the url of your form. Like so:
Update:
I suppose the page you are sending this request from is the same url as the one you are trying to post to. In this case the best thing to do would be to leave the action field of your form empty. This will make sure the form is submitted to the same url.
So you can just do this: