php - 保护特定请求类型、restful API、Laravel

标签 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
}

最佳答案

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

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

这是api page供引用。

关于php - 保护特定请求类型、restful API、Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14865914/

相关文章:

php - 我正在尝试使用 PHP 和 MySql 渲染 google 图表,但没有渲染图表,也没有显示错误消息。 html代码是否正确?

php - MySQL语法从多个符合条件的选项中选择表名

java - 传入多部分请求的快速 "preview"

javascript - 如何将 Controller session 中的值传递到 PHP laravel View Blade ?

javascript - 无法使用 session 变量来存储数据

php - 如何在 WordPress 中使用 jQuery Cycle 插件?

json - ReSTLet 使用 json 接收和响应实现 post

REST API - 当搜索条件 (queryParams) 没有产生任何结果时返回什么

php - Laravel/Nginx : 403 forbidden on middleware routes

php - Laravel 5.0 在源代码中最后生成 app.blade.php