Check if request is GET or POST

后端 未结 6 1216
离开以前
离开以前 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:16

    I've solve my problem like below in laravel version: 7+

    **In routes/web.php:**
    Route::post('url', YourController@yourMethod);
    
    **In app/Http/Controllers:**
    public function yourMethod(Request $request) {
        switch ($request->method()) {
            case 'POST':
                // do anything in 'post request';
                break;
    
            case 'GET':
                // do anything in 'get request';
                break;
    
            default:
                // invalid request
                break;
        }
    }
    

提交回复
热议问题