Support the ongoing development of Laravel.io →
Requests Views Forms

I have a form here as below:

	<form action="{{ route('benice') }}" method="post">
		<label for="select-action">I want to ...</label>
		<select id="select-action" name="action">
			<option value="greet">greet</option>
			<option value="hug">hug</option>
			<option value="kiss">kiss</option>
		</select>
		<input type="text" name="name"/>
		<button type="submit">Do a nice action!</button>
		<input type="hidden" value="{{ Session::token() }}" name="_token">
	</form>

and here I edit the route to catch the URL:

   //Post Requests
   Route::post('/benice', function(\Illuminate\Http\Request $request) {
	if (isset($request['action']) && $request['name']) {
		if(strlen($request['name']) > 0) {
		   return view('actions.nice', ['action'=>$request['action'], 'name'=>$request['name']]);
		}
		return redirect()->back();
	}

	return redirect()->back();
});

why do I get this error?

Last updated 3 years ago.
0
moderator Solution

You need to give your route a name. '/benice' is only the url segment. See here how to name routes: https://laravel.com/docs/5.2/routing#named-routes

0

i am wiring code it will be work

Route::post('/benice', function(\Illuminate\Http\Request $request) { if(isset($request['action']) && $request['name']) { if (strlen($request['name']) > 0) { return view('actions.nice', ['action' => $request['action'], 'name' => $request['name']]); } return redirect()->back(); } return redirect()->back(); })->name('benice');

0

the route in web.php should be :

Route::post('/benice', function(\Illuminate\Http\Request $request) {

if (isset($request['action']) && $request['name']) {
	if(strlen($request['name']) > 0) {
	   return view('actions.nice', ['action'=>$request['action'], 'name'=>$request['name']]);
	}
	return redirect()->back();
}

return redirect()->back();

})->name('benice');

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

samantaba samantaba Joined 26 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.