7nohe / laravel-typegen

The library lets you generate TypeScript types from your Laravel code
79 stars 5 forks source link

Generate the props type for a Page from a Controller action #14

Open 7nohe opened 1 year ago

7nohe commented 1 year ago

Let's assume we have a PostsController like the following in a Laravel project:

class PostsController extends Controller
{
    public function index()
    {
        $posts = Post::all();
        return Inertia::render(
            'Posts/Index',
            [
                'posts' => $posts
            ]
        );
    }
}

This code generates a props type called PostsIndexProps, which can be used as follows:

<script setup lang="ts">
import { PostsIndexProps } from '@/types/props';
const page = usePage<PostsIndexProps>()
</script>
prismosoft commented 1 year ago

That would be great!