2013-02-14 58 views
2

我想只保護POST請求到我的索引,我該怎麼做?保護特定的請求類型,寧靜的API,Laravel

public $restful = true; 

public function __construct() 
{ 
    parent::__construct(); 
      //this does not work 
    $this->filter('before', 'auth')->only(array('post_index')); 
} 

public function get_index() 
{ 
      //I do not want to protect this 
    return Response::eloquent(Model::all()); 
} 

public function post_index() 
{ 
      //I want to protect only this call 
} 

回答

4

你快到了!如果您只想保護POST請求,請使用only()on()方法的組合。試試:

$this->filter('before', 'auth')->only('index')->on('post'); 

這裏是api page作爲參考。

+0

太棒了!謝謝! – 2013-02-14 00:51:18