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 \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";
}
}