--- title: "Svelte Kit Development Workflow" description: "Daily commands for the Svelte kit and step-by-step guides to adding a page and a form, plus type checking with svelte-check and linting with ESLint and Prettier." --- # Development ## Daily workflow | Command | What it does | | --- | --- | | `composer dev` | Runs `php artisan serve`, `queue:listen`, `pail` and `npm run dev` together | | `npm run dev` | Vite dev server with HMR; also regenerates Wayfinder files | | `npm run build` | Production build to `public/build` | | `npm run build:ssr` | Client and SSR bundle (`vite build && vite build --ssr`) | | `php artisan erag:generate-lang` | Export `lang/*` to `resources/js/lang/*.json` | | `php artisan wayfinder:generate --with-form` | Regenerate `@/routes` and `@/actions` without Vite running | The complete list is on the [Commands](/docs/reference/commands) page. ::: tip Change not showing up in the browser? Make sure `npm run dev` (or `composer dev`) is running, or run `npm run build`. ::: ## Adding a page We'll walk through adding a Reports page to the Dashboard module, served at `/reports`. You'll find the full code for each step in the collapsible blocks further down. ```text route (module web.php) → controller → Inertia::render('reports/Index') → resources/js/pages/reports/Index.svelte → translations → permission + menu → test ``` 1. Add the route to `Modules/Dashboard/routes/web.php`. It goes inside the `auth` + `verified` group, with the `permission:View Reports|View Tenant Reports` middleware and the name `reports.index`. 2. Create the controller at `Modules/Dashboard/Http/Controllers/ReportController.php`. Keep it thin and put any business logic in `Modules//Services`. The controller renders the page by its path under `resources/js/pages`, which is PascalCase in this kit: `Inertia::render('reports/Index', …)`. 3. Create the page at `resources/js/pages/reports/Index.svelte`. Breadcrumbs go in `
    {#each reports as report (report.id)}
  • {report.name}
  • {/each}
``` ::: ::: details Steps 5–7: translations, permissions and seeding ```php // lang/en/modules/dashboard.php 'reports' => [ 'title' => 'Reports', 'description' => 'Exported analytics reports.', ], ``` ```php // config/permissions/dashboard.php (central) [ 'permission_name' => 'View Reports', 'associated_roles' => ['Super Admin', 'Admin'], ], // config/permissions/tenant/dashboard.php (tenant) [ 'permission_name' => 'View Tenant Reports', 'associated_roles' => ['Super Admin', 'Admin'], ], ``` ```bash php artisan erag:generate-lang php artisan db:seed --class=PermissionSeeder php artisan tenants:seed --class="Database\Seeders\PermissionSeeder" php artisan db:seed --class=MenuSeeder ``` ::: ::: details Step 8: feature test ```php use App\Models\User; use Inertia\Testing\AssertableInertia as Assert; use Spatie\Permission\Models\Permission; test('users with the permission can visit the reports page', function () { $user = User::factory()->create(); $user->givePermissionTo(Permission::findOrCreate('View Reports', 'web')); $this->actingAs($user) ->get(route('reports.index')) ->assertInertia(fn (Assert $page) => $page->component('reports/Index')); }); ``` Run it with `php artisan test --compact --filter=reports`. Since `config/inertia.php` turns on `testing.ensure_pages_exist`, the test will fail if `reports/Index.svelte` doesn't exist. ::: ::: info When a user is given a system role after seeding, they pick up the permission through `associated_roles`. For users you already have, grant it from **Users → Assign permissions**. [Users, roles & permissions](/docs/core/users-roles-permissions) explains how this works. ::: ## Adding a form A form posts to a controller action using Wayfinder and Inertia's `
` component. If you want something to copy, look at the roles form (`RoleController`, `RoleData`, `pages/roles/Partials/RoleFormModal.svelte`). 1. Validate on the server. We use Spatie Data classes for this (for example `Modules/RolePermission/Data/RoleData.php`, which has a `rules()` method), type-hinted in the controller action. 2. Let the controller hand the work to a service, flash a toast with `Inertia::flash('toast', …)` and redirect. 3. Add a route to the module's `routes/web.php`, with a name and the permission middleware. 4. Build the form: spread the Wayfinder `.form()` object into ``, then add `Common*` inputs with `name` and `error`. ```svelte {#snippet children({ errors, processing })} {__('modules.role.form_modal.create')} {/snippet} ``` Validation errors show up in `errors` without any extra code, and `lib/flash-toast.ts` displays the flashed toast. For edit forms, `useForm` and create/edit modals, see [Inertia → Forms](/docs/svelte/inertia#forms). ## Type checking & linting | Command | What it runs | | --- | --- | | `npm run lint` | `eslint .`, `prettier --check resources/`, `svelte-check --tsconfig ./tsconfig.json` | | `npm run lint:fix` | `eslint . --fix`, `prettier --write resources/`, `svelte-check --tsconfig ./tsconfig.json` | | `npx svelte-check --tsconfig ./tsconfig.json` | Type check only | | `composer lint` | Pint, `php artisan typescript:transform`, `npm run lint:fix` | | `composer test` | `config:clear`, `composer lint:check`, Larastan (`composer types:check`), then `php artisan test` | Get into the habit of running `npm run lint:fix` before you commit. ## Conventions - Don't hard-code text. Every string the user sees goes through `__()` with a `modules..` key, and that includes breadcrumbs, placeholders, toasts and confirm dialogs. - Build form fields and buttons from the `Common*` components, and ask before destructive actions with `useConfirmDialog()`. - Use Wayfinder rather than typing URLs by hand, and pair `.form()` with `
`. - Type everything. Data objects get the generated types from `@/types/Modules/...`, and type-only imports use `import type` (ESLint will remind you). - Hide actions the user isn't allowed to take with `usePermission()`, for example `can('Export Analytics Reports', 'Export Tenant Reports')`. See [Architecture → Permissions](/docs/svelte/architecture#permissions-on-the-frontend). - Put shared logic in `lib/` (as a `.svelte.ts` file if it needs runes). Components that belong to a single page go in that page's `Partials/` folder.