Skip to content

[5.x] Set the hidden attributes programmaticaly #283

@papac

Description

@papac

The hidden attributes do not show the attributes where user try to show the model as json format.

It's actually made from the model property like this

class UserModel extens Model
{
    /**
     * The hidden attributes
     *
     * @var array
     */
    protected array $hidden = [
        "created_at",
        "updated_at",
    ];

For this cas the hidden attributes should be made programmaticaly.

  $user->setHiddenAttributes(["password"]);

The short code for implementing the method:

    /**
     * Set the hidden attributes
     *
     * @param array $attributes
     */
    public function setHiddenAttributes(array $attributes)
    {
        $this->hidden = array_merge($this->hidden, $attributes);
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

🔖 Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions