保护特定的请求类型,宁静的API,Laravel

时间:2013-02-14 00:38:43

标签: php rest laravel

我只想保护对索引的POST请求,我该怎么办?

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
}

1 个答案:

答案 0 :(得分:4)

你快到了!如果您只想保护POST请求,请使用only()on()方法的组合。尝试:

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

以下是api page供参考。