我在路径文件夹中的web.php中有他的代码:
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();
});
,这是在view.blade.php里面的视图文件夹:
<form action="{{ route('benice') }}" method="post">
<label for="select-action">Iwant 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" class="btn btn-primary btn-block">Do an action</button>
<input type="hidden" value="{{ Session::token() }}" name="_token">
</form>
错误是:
Route [benice] not defined. (View: C:\wamp64\www\testLaravel\resources\views\home.blade.php)
anyhelp将会受到赞赏,我目前是laravel的新手,还在学习谢谢
答案 0 :(得分:6)
路线名称与路线路径不同。
将名称添加到路线中,如下所示:
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');
答案 1 :(得分:0)
从您的路线开始删除/
Route::post('benice', ...