laravel-typegen icon indicating copy to clipboard operation
laravel-typegen copied to clipboard

Generate the props type for a Page from a Controller action

Open 7nohe opened this issue 1 year ago • 1 comments

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>

7nohe avatar Apr 26 '23 13:04 7nohe

That would be great!

prismosoft avatar Jul 21 '23 19:07 prismosoft