Laravel 5.2 中的表格未找到路线
Form in Laravel 5.2 does not find route
我正在尝试通过表单制作一个简单的 post,路由存在并且令牌在那里,但是当提交时总是 returns '404 Not Found'。
路线:
Route::group(['middleware' => ['web']], function () {
Route::post('/cadastro', 'UsuarioPost@cadastro');
});
UsuarioPost 控制器:
class UsuarioPost extends Controller
{
public function cadastro(Request $request)
{
return dd($_POST);
}
}
查看表格:
<form id="f_cadastro" method="POST" action="{{ URL::to('/cadastro') }}">
{{ csrf_field() }}
<button type="submit">Cadastrar</button>
</form>
从 laravel 5.1 到 5.2 的表单提交有什么新东西吗?
即使在路线中没有组,这在以前的版本中也能正常工作。
我建议你用named routes代替这个策略,比较方便。
Route::get('/profile', [
'as' => 'profile.index',
'uses' => 'ProfileController@index',
]);
然后您可以仅使用
从您的视图或代码中生成 url
{{ route('profile.index') }}
所以,终于工作了。
这笔交易是与 apache 达成的,而不是 laravel。 Apaches httpd.conf 文件 (apaches directory/conf/httpd.conf) 默认禁用 AllowOverride,这是 laravel 所需要的。所以我必须将每个 "AllowOverride none" 更改为 "AllowOverride all",并删除行 "Require all denied"。
将我的 apache DocumentRoot 设置为我项目中的 public 文件夹一切正常。
我正在尝试通过表单制作一个简单的 post,路由存在并且令牌在那里,但是当提交时总是 returns '404 Not Found'。
路线:
Route::group(['middleware' => ['web']], function () {
Route::post('/cadastro', 'UsuarioPost@cadastro');
});
UsuarioPost 控制器:
class UsuarioPost extends Controller
{
public function cadastro(Request $request)
{
return dd($_POST);
}
}
查看表格:
<form id="f_cadastro" method="POST" action="{{ URL::to('/cadastro') }}">
{{ csrf_field() }}
<button type="submit">Cadastrar</button>
</form>
从 laravel 5.1 到 5.2 的表单提交有什么新东西吗? 即使在路线中没有组,这在以前的版本中也能正常工作。
我建议你用named routes代替这个策略,比较方便。
Route::get('/profile', [
'as' => 'profile.index',
'uses' => 'ProfileController@index',
]);
然后您可以仅使用
从您的视图或代码中生成 url{{ route('profile.index') }}
所以,终于工作了。
这笔交易是与 apache 达成的,而不是 laravel。 Apaches httpd.conf 文件 (apaches directory/conf/httpd.conf) 默认禁用 AllowOverride,这是 laravel 所需要的。所以我必须将每个 "AllowOverride none" 更改为 "AllowOverride all",并删除行 "Require all denied"。
将我的 apache DocumentRoot 设置为我项目中的 public 文件夹一切正常。