检查请求是GET还是POST [英] Check if request is GET or POST

查看:89
本文介绍了检查请求是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆