Hide exposed routes when using Ziggy

Hey everyone 👋

Have you guys tried hiding the generated routes of Ziggy when using Inertia?

Typical setup

    <!-- Scripts -->
    @routes
    @vite(['resources/js/app.js'])
    @inertiaHead
</head>
<body class="font-sans antialiased">
    @inertia
</body>

If you're using php artisan ziggy:generate how do you set it up properly?

whoami (Daryl)
whoami (Daryl)
0
2
608
Haz
Haz
Moderator
Solution

Hello,

That's what that library does. It. exposes your routes.

I may have misguided you previously in your other thread. You don't need to actually use the ziggy-js library.

Ziggy Installation

In your HandleInertiaRequests middleware, just use the following.

            'ziggy' => function () use ($request) {
                return array_merge((new Ziggy())->toArray(), [
                    'location' => $request->url(),
                ]);
            },

In your app.js, you still need the following.

import { ZiggyVue } from "ziggy";

...
...
...
            .use(ZiggyVue, Ziggy)

In your ssr.js, you need the following.

import { ZiggyVue } from "ziggy";

...
...
...
                .use(ZiggyVue, {
                    ...page.props.ziggy,
                });

The route helper should be globally available.

php artisan ziggy:generate

You don't need to use this either.

You can also delete the ziggy.js file in your resources/js folder.

whoami (Daryl)
whoami (Daryl)

Hey Haz,

Thank you so much for pointing that out, will update my code 🎉