lepikhinb / laravel-typescript

MIT License
387 stars 46 forks source link

feat: generate interfaces from resources #1

Closed ibrunotome closed 3 years ago

ibrunotome commented 3 years ago

Hi! What do you think about generation from Resources? e.g:

/**
 * @mixin \App\Models\Ticket
 */
class SupportResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request): array
    {
        return [
            'id'         => $this->id,
            'title'      => $this->title,
            'message'    => $this->message,
            'created_at' => $this->created_at->diffForHumans(),
            'category'   => [
                'title' => $this->category->short_title,
                'hex_color'   => $this->category->hex_color,
            ],
            'status'     => [
                'title'     => $this->status->title,
                'hex_color' => $this->status->hex_color,
            ],
        ];
    }
}

It's possible? If it is, it will be a consistent interface in the backend and frontend.

lepikhinb commented 3 years ago

This one would be kinda tricky, as it probably requires the actual token parsing. However, I'll try to get back to this.

lepikhinb commented 3 years ago

Closing for a while.

GENL commented 2 years ago

It would be great,

sawirricardo commented 2 years ago

@lepikhinb any update on this? This one will be good since many of us use laravel resource

neoighodaro commented 1 year ago

Any update? Would be nice to have this tbh

mxaGianluca commented 1 year ago

I’ve had a stab at this and created a package that tries to solve this, i’m not sure if it’s bad practice to share it here that’s why I’d like to ask it first. (If it is, feel free to remove my comment)