PHP code example of jpnut / laravel-typescript-codegen

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

    

jpnut / laravel-typescript-codegen example snippets


    // routes/web.php

    ...

    Route::delete('/foo/{foo}', FooController::class.'@delete')->name('foo.delete');

    ...

    // App\Controllers\Web\FooController

    ...

    /**
     * @code-gen
     */
    public function delete(Request $request, Foo $foo): bool
    {
        return $foo->delete();
    }

    ...

...

/**
 * @code-gen
 */
public function delete(Request $request, Foo $foo): bool

...

// App\Objects\User

...

class User
{
    public string $name;

    public int $age;

    /**
     * App\Object\Token[]
     */
    public array $tokens;
}

// App\Requests\UpdateUserRequest

...

class UpdateUserRequest extends FormRequest
{
    /**
     * @code-gen-property body
     */
    public function data(): UpdateUserParams
    {
        return new UpdateUserParams([
            'name' => $this->input('name'),
            'age' => $this->input('age'),
        ]);
    }
}

// App\Objects\UpdateUserParams

...

class UpdateUserParams
{
    ...

    public ?string $name;

    public ?int $age;
}

class Foo {
    /**
     * @code-gen-ignore
     */
    public string $ignored_property;
}
shell script
php artisan vendor:publish --provider="JPNut\CodeGen\CodeGenServiceProvider" --tag="config"