laravel 抛出 MethodNotAllowedHttpException [英] laravel throwing MethodNotAllowedHttpException
问题描述
我正在尝试运行一些非常基本的东西.我习惯了 CI,现在正在学习 Laravel 4,他们的文档并不容易!无论如何,我正在尝试创建一个登录表单,并通过在下一个表单中打印来确保数据已成功发布.我收到此异常:
I am trying to get something very basic running. I am used to CI and now learning Laravel 4, and their docs are not making it easy! Anyways, I am trying to create a login form and just make sure that data is posted successfully by printing it in the next form. I am getting this exception:
Symfony组件HttpKernel异常MethodNotAllowedHttpException
Symfony Component HttpKernel Exception MethodNotAllowedHttpException
和我的 MemberController.php:
and my MemberController.php:
public function index()
{
if (Session::has('userToken'))
{
/*Retrieve data of user from DB using token & Load view*/
return View::make('members/profile');
}else{
return View::make('members/login');
}
}
public function validateCredentials()
{
if(Input::post())
{
$email = Input::post('email');
$password = Input::post('password');
return "Email: " . $email . " and Password: " . $password;
}else{
return View::make('members/login');
}
}
和路线有:
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/members', 'MemberController@index');
Route::get('/validate', 'MemberController@validateCredentials');
最后我的视图 login.php 有这个表单方向:
and finally my view login.php has this form direction:
<?php echo Form::open(array('action' => 'MemberController@validateCredentials')); ?>
任何帮助将不胜感激.
推荐答案
您收到该错误是因为您要发布到 GET
路由.
You are getting that error because you are posting to a GET
route.
我会将您的 validate
路由拆分为单独的 GET
和 POST
路由.
I would split your routing for validate
into a separate GET
and POST
routes.
新路线:
Route::post('validate', 'MemberController@validateCredentials');
Route::get('validate', function () {
return View::make('members/login');
});
那么你的控制器方法可能只是
Then your controller method could just be
public function validateCredentials()
{
$email = Input::post('email');
$password = Input::post('password');
return "Email: " . $email . " and Password: " . $password;
}
这篇关于laravel 抛出 MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!