Check if request is GET or POST

后端 未结 6 1215
离开以前
离开以前 2021-02-04 23:37

In my controller/action:

if(!empty($_POST))
{
    if(Auth::attempt(Input::get(\'data\')))
    {
        return Redirect::intended();
    }
    else
    {
                


        
6条回答
  •  孤城傲影
    2021-02-05 00:31

    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);
    

    inside you controller/action

    if(Auth::attempt(Input::get('data')))
    {
       return Redirect::intended();
    }
    //You don't need else since you return.
    Session::flash('error_message','');
    

    The same goes for GET request.

    Route::get('url', YourController@yourGetMethod);
    

提交回复
热议问题