检查请求是GET还是POST [英] Check if request is GET or POST
本文介绍了检查请求是GET还是POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的控制器/操作中:
In my controller/action:
if(!empty($_POST))
{
if(Auth::attempt(Input::get('data')))
{
return Redirect::intended();
}
else
{
Session::flash('error_message','');
}
}
Laravel
中是否有一种方法可以检查请求是POST
还是GET
?
Is there a method in Laravel
to check if the request is POST
or GET
?
推荐答案
Of course there is a method to find out the type of the request, But instead you should define a route that handles POST
requests, thus you don't need a conditional statement.
routes.php
Route::post('url', YourController@yourPostMethod);
您内部的控制器/操作
if(Auth::attempt(Input::get('data')))
{
return Redirect::intended();
}
//You don't need else since you return.
Session::flash('error_message','');
GET
请求也是如此.
Route::get('url', YourController@yourGetMethod);
这篇关于检查请求是GET还是POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文