TP5.1 使用Collection对不同接口隐藏不同的字段

1、在Config文件里的dataBase.php字段 resultset_type 设置为 'collection'

2、使用model查询数据时,

  a、以find结尾的查询,返回的是数组,需要使用Collection类将数组转为数据集,如:

    // 通过数据集隐藏接口不需要的字段参数,而不影响其他接口
        $collection = Collection::make($result);
        $result = $collection->hidden(['summary']);    

  b、以select结尾的查询,返回的Collection集,则直接使用,如:

    $result = $result->hidden(['summary']);

    

猜你喜欢

转载自www.cnblogs.com/PLA-Artillery/p/9205327.html
今日推荐