【问题标题】:Protecting specific request types, restful API, Laravel保护特定请求类型、restful API、Laravel
【发布时间】:2013-01-29 17:29:29
【问题描述】:

我只想保护对我的索引的 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
}

【问题讨论】:

    标签: php rest laravel


    【解决方案1】:

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

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

    这是api page 供参考。

    【讨论】:

      猜你喜欢
      • 2015-02-03
      • 1970-01-01
      • 2019-01-25
      • 2018-09-13
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      相关资源
      最近更新 更多