PHP code example of hemilrajput / laravel-typegen

1. Go to this page and download the library: Download hemilrajput/laravel-typegen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hemilrajput / laravel-typegen example snippets


enum UserRole: string {
    case Admin = 'admin';
}

class User extends Model {
    protected $casts = ['role' => UserRole::class];
}

use Hemilrajput\TypeGen\Attributes\TypeScript;

#[TypeScript]
class User extends Model { ... }

#[TypeScript(xtends Model { /* ... */ }

Relation::enforceMorphMap([
    'post' => Post::class,
    'video' => Video::class,
]);
bash
php artisan typescript:generate
ts
export interface User {
  id: number;
  posts?: Post[];
  profile?: Profile | null;
}

export interface Post { /* ... */ }
export interface Profile { /* ... */ }
ts
export interface Comment {
  commentable?: (Post | Video) | null;
}