# Inertia Page Ctrl

> Create a Go page controller that serves an Inertia.js page. Configures the EntityPageController with service, permissions, and optional stats. Use when this capability is needed.

- Skill: `tomevault-io/inertia-page-ctrl` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/inertia-page-ctrl`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/inertia-page-ctrl/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/inertia-page-ctrl

---


# Inertia Page Controller (Go Backend)

Create page controller for `$ARGUMENTS`.

## Step 1: Generate Page Controller

```bash
go run . artisan make:page-ctrl --controller=$ARGUMENTS
```

This creates `app/http/controllers/<entity>s/<entity>s_page_controller.go`.

## Step 2: Configure the Controller

```go
package entitynames

import (
    "books-database/app/auth"
    "books-database/app/contracts"
    "books-database/app/services"
)

type EntityPageController struct {
    *contracts.GenericPageController
    entityService *services.EntityService
}

func NewEntityPageController() *EntityPageController {
    entityService := services.NewEntityService()

    return &EntityPageController{
        GenericPageController: contracts.NewGenericPageController(contracts.GenericPageConfig{
            ResourceType:      "entities",               // Plural snake_case
            PageComponent:     "Entity/Index",           // React component path under resources/js/pages/
            Service:           entityService,
            ServiceIdentifier: auth.ServiceEntity,       // From permission_constants.go
            StatsEnabled:      false,                    // Set true for badge counts
            // StatsBuilder: func(controller *contracts.GenericPageController) map[string]interface{} {
            //     stats, _ := entityService.GetEntityStatistics()
            //     return stats
            // },
        }),
        entityService: entityService,
    }
}
```

## Configuration Fields

| Field | Purpose | Example |
|---|---|---|
| `ResourceType` | Plural snake_case resource name | `"configs"`, `"books"` |
| `PageComponent` | React component path | `"Config/Index"`, `"Book/Index"` |
| `Service` | CRUD service instance | `configService` |
| `ServiceIdentifier` | Permission service constant | `auth.ServiceConfig` |
| `StatsEnabled` | Enable statistics | `true` / `false` |
| `StatsBuilder` | Function returning stats map | See template above |

## Props Passed to React

The `GenericPageController.Index()` method automatically passes:

```typescript
{
    data: PaginatedResult<Entity>,     // Paginated entity list
    filters: ListRequest,               // Current page/sort/search/filter state
    permissions: {
        canCreate: boolean,
        canEdit: boolean,
        canDelete: boolean,
    },
    stats?: Record<string, any>,        // If StatsEnabled=true
    meta: {
        pagination: {
            defaultPageSize: number,
            maxPageSize: number,
            allowedSizes: number[],
        },
    },
}
```

## Step 3: Register Web Route

In `routes/web.go`:

```go
// Import
entityPageController := entitynames.NewEntityPageController()

// Route (inside authenticated middleware group)
router.Get("/admin/entity-names", entityPageController.Index)
```

## Step 4: Adding Statistics (Optional)

If you want badge counts on simple filters, create a statistics method on the service:

```go
func (s *EntityService) GetEntityStatistics() (map[string]interface{}, error) {
    var totalCount, activeCount, inactiveCount int64

    totalCount, _ = facades.Orm().Query().Model(&models.Entity{}).Count()
    activeCount, _ = facades.Orm().Query().Model(&models.Entity{}).Where("status = ?", "ACTIVE").Count()
    inactiveCount, _ = facades.Orm().Query().Model(&models.Entity{}).Where("status = ?", "INACTIVE").Count()

    return map[string]interface{}{
        "totalCount":    totalCount,
        "activeCount":   activeCount,
        "inactiveCount": inactiveCount,
    }, nil
}
```

Then enable in page controller:
```go
StatsEnabled: true,
StatsBuilder: func(controller *contracts.GenericPageController) map[string]interface{} {
    stats, _ := entityService.GetEntityStatistics()
    return stats
},
```

## Verify

After configuring the page controller and registering the web route:

```bash
# Vet the controllers package
go vet ./app/http/controllers/...

# Confirm full project compiles
go build ./...
```

## Reference

See `app/http/controllers/configs/configs_page_controller.go` for a complete example.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/liwoo) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-11 -->

