2015-07-10 63 views
2

当我需要在laravel中创建某种形式的表单时,我使用单一路由进行表单显示和保存。出于这个原因,我需要使用Route::any('login', '[email protected]')这不正确。Laravel:在单一路径中的表单显示和逻辑

比如我典型的登录表单控制器的方法:

public function login() 
{ 
    // handle submit 
    if(\Input::isMethod('post')) 
    { 
     if(\Auth::attempt(array('username' => \Input::get('username'), 'password' => \Input::get('password')))) 
     { 
      return \Redirect::intended('profile'); 
     } else { 
      return \Redirect::back()->withInput() 
       ->withErrors(['auth-validation' => 'Invalid username or password']); 
     } 
    } 

    // show form 
    $this->layout->content = \View::make('frontend/login'); 
} 

的问题是:有没有其他Route::any或任何东西,我不能从长远来看想到的任何安全隐患?

回答

1

任何安全风险只取决于您对请求实际做了什么以及您使用哪些条件和/或检查来响应不同的动词。

但是,你可以限制动词与match()方法,而不是any()

Route::match(['GET', 'POST'], '/uri', '[email protected]'); 
+0

没知道有这样的方法,这似乎是更好的方法来路由这种事情,非常感谢! – insanebits