What is Runtype for Laravel?
Runtype for Laravel is a package that allows you to generate Typescript interfaces from your Laravel Models & Resources.
This resource:
php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin \App\Models\Product */
class ProductResource extends JsonResource
{
public $showHiddenData = false;
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'hidden' => $this->when($this->showHiddenData, false),
];
}
}will generate this Typescript type:
typescript
declare namespace App.Http.Resources {
export type ProductResourceType = {
id: number;
name: string;
hidden?: boolean;
}
}