Passing variable with route parameter when form is submitted Laravel 5.2

36,086

Solution 1

Laravel 5.2 Missing required parameters for [Route: user.profile] [URI: user/{nickname}/profile]

Using the above link I found a solution.. I changed:

<form action="{{ route('test.route'), ['id' => $params_id] }}" method="POST" >

to

<form action="{{ route('test.route', [$params_id]) }}" method="GET" >

and this:

Route::post('/testing/{{id}}',[
     'uses' => 'TestController@testMethod', 
     'as' => 'test.route'
]);

to

Route::get('/testing/{id}',[
     'uses' => 'TestController@testMethod', 
     'as' => 'test.route'
]);

and for reading value :

if ($request->id) {
}

And It works! But I wonder if anyone else can get a POST version working, or is GET the only way? I dont really know much about GET/POST request, only that it's used in forms and ajax.. Would really like to learn more about HTTP GET/POST, if anyone has anything to add please share!! thanks! Hope this answer will help someone!

Solution 2

Although it's an old post hopefully it will help others in future. For me in Laravel 5.8 the POST method just worked fine.

HTML form:

<form method="POST" role="form" action="{{route('store_changed_role', [$user_id, $division_id])}}">

Route:

Route::post('/sotre_changed_role/{user_id}/{division_id}', 'Admin\UserController@store_changed_role')->name('store_changed_role');

Solution 3

For me this worked pretty well.

{{ Form::open(array('route' => array('user.show', $user->id))) }}

with class name

{{ Form::open(array('route' => array('user.show', $user->id), 'class' => 'section-top')) }}
Share:
36,086
OzmaTis
Author by

OzmaTis

Updated on July 10, 2022

Comments

  • OzmaTis
    OzmaTis almost 2 years

    I have this in my form in the viewpage.php:

    <form action="{{ route('test.route'), ['id' => $params_id] }}" method="POST" >
    

    And this in the route.php:

    Route::post('/testing/{{id}}',[
        'uses' => 'TestController@testMethod', 
        'as' => 'test.route'
    ]);
    

    And this is my TestController:

    public function avaliarSubordinor(Request $request, $uid){
        return $uid;
    }
    

    I get an error which says 'Missing required parameters for[Route: test.route] [URI: testing/{{id}}]. Essentially What i want is to pass a variable to my controller using a route with a parameter when form is submitted..

    I dont know if I am doing this properlly..if anyone can help me or point me to an example so i can understand what I am doing wrong..