<?php
/**
 * Created by PhpStorm.
 * User: radko
 * Date: 2018-12-13
 * Time: 13:44
 */

namespace Seka\Vzdelavanie\Http\Resources;

/**
 * Trait HideResourceFieldsTrait
 * @package Seka\Vzdelavanie\Http\Resources
 */
trait HideResourceFieldsTrait
{
    /**
     * @var array
     */
    protected $withoutFields = [];

    /**
     * Set the keys that are supposed to be filtered out.
     *
     * @param array $fields
     * @return $this
     */
    public function hide(array $fields)
    {
        $this->withoutFields = $fields;

        return $this;
    }

    /**
     * Remove the filtered keys.
     *
     * @param $array
     * @return array
     */
    protected function filterFields($array)
    {
        return collect($array)->forget($this->withoutFields)->toArray();
    }
}
