PHP code example of wovosoft / laravel-typescript

1. Go to this page and download the library: Download wovosoft/laravel-typescript 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/ */

    

wovosoft / laravel-typescript example snippets


return [
    'output_path'       => resource_path('js/types/models.d.ts'),
    'source_dir'        => app_path('Models'),
    /**
     * Custom attributes should have return types defined.
     * But if it is not, then the return type should be this type.
     * And this value should be php supported return types.
     * like primitive types or any other classes
     */
    "custom_attributes" => [
        "fallback_return_type" => "string"
    ]
];

use Wovosoft\LaravelTypescript\Facades\LaravelTypescript;


$dirs = [
    "models"               => app_path("Models"),
    "hrmPerson"            => base_path("packages/wovosoft/hrms-person/src/Models"),
];

foreach ($dirs as $name => $dir) {
    LaravelTypescript::generate(
        sourceDir : $dir,
        outputPath: resource_path("js/types/$name.d.ts")
    );
    
    echo "Generated $name.d.ts";
}

use \Illuminate\Database\Eloquent\Model;
use \Illuminate\Database\Eloquent\Casts\Attribute;

class User extends Model{
    public function isActive() : Attribute 
    {
        return Attribute::get(fn(): bool =>$this->status==='active');
    }
    
    public function getIsInactiveAttribute():bool
    {
        return $this->status==="inactive";
    }
}
bash
php artisan vendor:publish --provider="Wovosoft\LaravelTypescript\LaravelTypescriptServiceProvider"
bash
php artisan laravel-typescript:transform