laravel-typescript
laravel-typescript copied to clipboard
Make ModelGenerator account for hidden fields
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;
}