voyager-admin/voyager

View on GitHub
docs/plugins/pages.md

Summary

Maintainability
Test Coverage
# Custom pages

This page shows how to add a custom page with a component only to logged-in users.  
You need to define and register a [component](/plugins/components) and add a [menu-item](/plugins/menu-items) to Voyager if you want.

```php
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Voyager\Admin\Contracts\Plugins\Features\Provider\ProtectedRoutes;

class MyPlugin implements ProtectedRoutes
{
    public function provideProtectedRoutes(): void
    {
        Route::get('my-page', function (Request $request) {
            // Trigger Voyager to inject some necessary dynamic data
            Inertia::setRootView('voyager::app');

            return Inertia::render('my-component', [
                'data' => []
            ])->withViewData('title', 'My page');
        });
    }
}
```