Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
papac opened this issue Dec 2, 2023 · 0 comments
Open

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

papac opened this issue Dec 2, 2023 · 0 comments
Assignees

Comments

@papac
Copy link
Member

papac commented Dec 2, 2023

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);
    }
@papac papac added this to v5 Dec 2, 2023
@papac papac self-assigned this Dec 2, 2023
@papac papac converted this from a draft issue Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔖 Ready
Development

No branches or pull requests

1 participant