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

namespace Seka\Portal\Modul\Vzdelavanie\Http\Resources;

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

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

        return $this;
    }

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