laravel-typegen
laravel-typegen copied to clipboard
Generate the props type for a Page from a Controller action
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>
That would be great!