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

Make ModelGenerator account for hidden fields #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsalex1
Copy link

@dsalex1 dsalex1 commented Jun 29, 2022

Make ModelGenerator filter out columns that have been hidden from the serialized representation of the Model (see: https://laravel.com/docs/9.x/eloquent-serialization#hiding-attributes-from-json).

The hidden attribute is commonly used with fields like password or remember_token.

Without filtering the types generated for a model misrepresent what is commonly sent by a server for this model:

{
  "id": 1,
  "name": "Test User",
  "email": "[email protected]",
  "email_verified_at": "2022-06-29T14:51:15.000000Z",
  "created_at": "2022-06-29T09:18:09.000000Z",
  "updated_at": "2022-06-29T09:18:09.000000Z"
}

for a generated type

export interface User {
    id: number;
    name: string;
    email: string;
    email_verified_at: string | null;
    created_at: string | null;
    updated_at: string | null;
}

instead of (without filtering hidden fields)

export interface User {
    id: number;
    name: string;
    email: string;
    password: string ;
    remember_token: string ;
    email_verified_at: string | null;
    created_at: string | null;
    updated_at: string | null;
}

Make ModelGenerator filter out columns that have been hidden from the serelized representation of the Model (see: https://laravel.com/docs/9.x/eloquent-serialization#hiding-attributes-from-json).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants