Laravel Go Best Practices
ASecurityBest practices for apps built with Laravel for Go (the go.laravel.com module, 0.1.x). Use when writing or reviewing Laravel for Go code: handlers, input structs, models and queries, transactions, policies, Inertia props, middleware, jobs, listeners, workflows, the scheduler, the HTTP client, services, configuration and deployment. Each rule shows the common version (usually code that compiles but behaves wrongly: columns zeroed by model.Save, another user's record served or changed, a job pus...
- 3 stars
- 0 votes
- 0 copies
- 0 views
- Added December 3, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add airshell/laravel-php-to-rust-go --skill laravel-go-best-practices --agent claude-codeAre you the author of Laravel Go Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/airshell-laravel-go-best-practices)---
name: laravel-go-best-practices
description: "Best practices for apps built with Laravel for Go (the go.laravel.com module, 0.1.x). Use when writing or reviewing Laravel for Go code: handlers, input structs, models and queries, transactions, policies, Inertia props, middleware, jobs, listeners, workflows, the scheduler, the HTTP client, services, configuration and deployment. Each rule shows the common version (usually code that compiles but behaves wrongly: columns zeroed by model.Save, another user's record served or changed, a job pushed for a rolled-back order, a panic into a 500, a goroutine that dies with the request, a job lost or run twice, a secret sent to the browser; a few are configuration or deploy mistakes) and the version to write. Every Go example compiles against go.laravel.com v0.1.0, and the main claims were tested on that version. Complements the seven skills a new app ships in .agents/skills/. Not for Laravel on PHP (use laravel-best-practices) or Laravel for Rust (use laravel-rust-best-practices)."
license: MIT
metadata:
author: airshell
version: "1.0.1"
laravelGoVersion: "0.1.x (tested 0.1.0)"
goVersion: "1.27+"
---
# Laravel for Go Best Practices
Best practices for apps built with [Laravel for Go](https://laravel.com/go) (`go.laravel.com` 0.1.x). Contains 42 rules across 7 categories. Every Go example compiles against `go.laravel.com` v0.1.0, and each "Tested on go.laravel.com v0.1.0" note records what a test on that version showed.
**Version 1.0.1 (December 2026).** Laravel for Go is in beta, and a minor version before 1.0 may change the API; check APIs against the docs bundled with the version you install (`.agents/skills/writing-laravel-go-apps/scripts/docs-path.sh`, which runs `go list -m -f '{{.Dir}}/docs' go.laravel.com`).
## When to Apply
- Writing handlers, input structs, models, queries, policies, middleware, jobs, listeners, workflows, scheduled tasks, services or configuration in a Laravel for Go app
- Reviewing Laravel for Go code before it ships
- Deciding between two ways the framework allows (`model.Save` or `model.Update`, `r.Bind` or `r.Validate`, `r.Background` or a queued job, `Send` or `Queue`)
## How This Skill Fits
A new app ships seven skills in `.agents/skills/` (writing, database, validation, auth, queues and workflows, testing, Inertia) that describe how the framework works. This skill adds what they leave out: the mistakes that compile and still behave wrongly, each with the version to write and, where it matters, a test that proves the difference.
- **Writing**: before writing code in an area below, read its rules and follow their Correct examples
- **Reviewing**: follow "Reviewing Laravel for Go Code" below
- Related skills: `laravel-go-testing` (tests), `laravel-inertia-react` (the React side of an Inertia app), `laravel-best-practices` (Laravel on PHP), `laravel-rust-best-practices` (Laravel for Rust)
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Data | CRITICAL | `data-` |
| 2 | Authorization | CRITICAL | `auth-` |
| 3 | Architecture | HIGH | `arch-` |
| 4 | HTTP | HIGH | `http-` |
| 5 | Runtime | HIGH | `run-` |
| 6 | Background Work | HIGH | `jobs-` |
| 7 | Operations | MEDIUM | `ops-` |
## Quick Reference
### 1. Data (CRITICAL)
- `data-update-not-save` - `model.Update` with the changed columns; `model.Save` writes every column; `Increment` for counters
- `data-transactions-use-the-callback-ctx` - Every call inside `db.Transaction` uses its `ctx`; a call with `r` runs outside it and pushes jobs before the commit; `LockForUpdate` to read, check and write
- `data-side-effects-after-commit` - `mail.Send` delivers even on rollback; `Queue` or `db.AfterCommit` waits for the commit
- `data-group-or-conditions` - `OrWhere` on a scoped or related query returns other users' rows; group it in `WhereGroup`
- `data-default-columns-need-pointers` - A zero value on a `db:",default"` field becomes the default; use a pointer
- `data-bulk-writes-skip-hooks` - Query `Update`/`Delete`, `Upsert`, `InsertMany` skip hooks and events
- `data-eager-load` - `With` every relationship a handler reads; unloaded ones are nil (panic) or empty (silent)
- `data-sort-allowlist` - Unknown columns panic; allow-list sort columns; `db.ParseDirection`
- `data-nullable-columns-and-aggregates` - One NULL in a field that cannot hold it fails the read; pointers or NULL-scanning types; `Avg[*float64]`
- `data-chunk-by-id-when-writing` - `Chunk` skips rows when the loop changes them; `ChunkByID`
- `data-pagination-keep-filters` - Order with a unique tie-breaker; use the paginator `Appends` returns
### 2. Authorization (CRITICAL)
- `auth-scope-nested-routes` - `model.Related(&parent, ..).FromRoute`, then the policy
- `auth-validate-runs-authorize` - A form's `Authorize` runs through `r.Validate`, never `r.Bind`
- `auth-exists-is-not-ownership` - `model.Exists(..).Where("user_id", ..)` and a scoped write
- `auth-guest-abilities` - `auth.Ability` denies guests before it runs; `auth.GuestAbility` and nil checks
- `auth-login-email-and-throttle` - `transform:"lowercase"` on the login email; `WithBucket` on the login throttle
### 3. Architecture (HIGH)
- `arch-env-through-services` - Read settings in `services.New` with `env.Require`, not `os.Getenv`
- `arch-services-hold-no-request-state` - Services are shared by every request; pass request values as arguments
### 4. HTTP (HIGH)
- `http-partial-updates` - `validation.Sometimes` so a PATCH does not clear omitted columns
- `http-errors-with-status` - Errors without a status are 500s; give expected errors a `StatusCode`
- `http-responses-send-only-needed` - Response structs, not models, in props and JSON
- `http-inertia-shared-props` - Share a user summary; `inertia.Lazy` for values the handler changes
- `http-middleware-after-auth-session` - Middleware that reads the user goes after `auth.Session`; `ActingAs` hides the bug
- `http-signed-urls-read-the-url` - The signature covers the URL, not the body
- `http-no-writes-on-get` - CSRF skips GET; never change data on GET routes
### 5. Runtime (HIGH)
- `run-background-not-go-func` - `r.Background` with its `ctx`, not a bare `go` with `r`; a panic in a bare goroutine ends the server
- `run-http-client` - `EnsureSuccessful`, a `Timeout`, and retries only for requests safe to repeat (reads, PUTs that replace a resource, writes with a key the provider deduplicates)
- `run-time-and-clock` - `date.Now(ctx)` so `client.Travel` works; times come back in UTC, truncated
### 6. Background Work (HIGH)
- `jobs-retries-are-opt-in` - Jobs run once by default; `Tries` and `Backoff`, or `RetryFor` for jobs that release
- `jobs-missing-models` - `FailWhenMissingModels` when a missing row means something went wrong
- `jobs-workflow-replay` - Every side effect inside a uniquely named step; no `defer` work
- `jobs-listener-errors` - A listener's error fails the dispatch; queue slow listeners, report the rest
- `jobs-stable-names` - `JobName` for long-lived jobs; dispatch values, not pointers
- `jobs-schedule-utc-names-and-locks` - UTC times, `Name` for a job type scheduled twice with locks, a shared cache for locks
### 7. Operations (MEDIUM)
- `ops-debug-and-error-messages` - `APP_DEBUG=false`; `Abortf` messages are public; `web.PublicMessage` in `Render`
- `ops-private-files` - Private files on a private disk (check `FILESYSTEM_DISK`), served by a handler that authorizes
- `ops-shared-cache-store` - `CACHE_STORE=database` or `redis` so restarts, locks and throttles reach every process
- `ops-deploy-checklist` - `SERVER_HOST`, shutdown timeout, `migrate --force`, `queue:restart`; `/up` is liveness only
- `ops-app-key-rotation` - `APP_PREVIOUS_KEYS` when the key changes (never for a leaked key)
- `ops-paths-from-base-path` - `StoragePath` and `PublicPath`, not paths relative to the working directory
- `ops-frontend-assets` - Build assets before the binary; never ship `public/hot`
- `ops-logging-with-context` - `slog.InfoContext` with fields; no secrets
## Reviewing Laravel for Go Code
1. **Build, vet and test**: `go build ./...`, `go vet ./...`, `go test ./...` (and `go test -race ./...` where the environment allows). The compiler already rejects misspelled form fields in `rule.Field(&f.X, ..)`; it does not catch the mistakes below, which all compile
2. **Search for these patterns.** A match is a place to read, not a finding
| Search for | What to confirm | Rule |
|---|---|---|
| `model.Save(` | The struct was loaded in this request and every field is meant to be written; otherwise `model.Update` with the changed columns, `Increment` for counters | `data-update-not-save` |
| `db.Transaction(r,` and code inside the callback that uses `r` | Every call inside uses the callback's `ctx` (or `db.Outside(ctx)` on purpose) | `data-transactions-use-the-callback-ctx` |
| `.Send(` of mail or notifications, HTTP calls inside `db.Transaction` | `Queue`, `db.AfterCommit`, or a queued job | `data-side-effects-after-commit` |
| `OrWhere` after `model.Related`, a scope, or a `user_id`/team condition | The or-conditions are inside `WhereGroup` | `data-group-or-conditions` |
| `db:",default"` on non-pointer fields | The zero value never needs to be stored | `data-default-columns-need-pointers` |
| `.Update(` / `.Delete(` on `model.Query`, `model.Upsert`, `model.InsertMany` on models with hooks or listeners | Nothing in a hook or listener must run | `data-bulk-writes-skip-hooks` |
| Reads of relationship fields (`post.User.`, `range post.Comments`) | `With`/`Load` on that query; nil checks for nullable `belongs_to` | `data-eager-load` |
| `OrderBy(` / `OrderByDirection(` with request input | An allow-list and `db.ParseDirection` | `data-sort-allowlist` |
| Plain fields (not pointers or NULL-scanning types such as `sql.NullString`) for `.Nullable()` columns; `Avg[`, `Min[`, `Max[` that can return NULL (no matching rows, or only NULL values), into a type that cannot hold NULL | Pointer or NULL-scanning types | `data-nullable-columns-and-aggregates` |
| `.Chunk(` with writes in the loop | `ChunkByID` | `data-chunk-by-id-when-writing` |
| `Paginate(`; `.Appends(` / `.WithQueryString(` on their own line | An order ending in a unique column; the returned paginator is used | `data-pagination-keep-filters` |
| Routes with two model parameters (`/{a}/.../{b}`) | The child is found through the parent with `model.Related(..).FromRoute` | `auth-scope-nested-routes` |
| `r.Bind[` / `BindInto(` | The type has no `Authorize` method, or the handler authorizes itself | `auth-validate-runs-authorize` |
| `model.Exists[` in rules, then writes by those IDs | The rule and the write are both limited to the user's rows | `auth-exists-is-not-ownership` |
| `auth.Ability` for pages guests can see; `CurrentUser(r).` on guest routes | `auth.GuestAbility` and nil checks | `auth-guest-abilities` |
| Login and sign-up forms; `ThrottlePer...` without `WithBucket` | `transform:"lowercase"` on the email; a bucket per sensitive route | `auth-login-email-and-throttle` |
| `os.Getenv(` | Read in `services.New` or config through `*config.Env` | `arch-env-through-services` |
| Fields on service structs that are set after `services.New` | Request values passed as arguments; shared state behind a mutex | `arch-services-hold-no-request-state` |
| `*string` fields in update forms copied into `db.Values` | `validation.Sometimes` when the client may leave fields out | `http-partial-updates` |
| `errors.New` / `fmt.Errorf` without `%w` for user mistakes returned to handlers | A `StatusCode` method or `web.Errorf` | `http-errors-with-status` |
| Models in `inertia.Props`, `web.JSON`, or `Share` (including models loaded with `With`) | A response struct | `http-responses-send-only-needed`, `http-inertia-shared-props` |
| `m.Web.Append` and `m.Global` with middleware that reads the user | Appended after `auth.Session` | `http-middleware-after-auth-session` |
| `ValidateSignature` routes whose handlers call `r.Bind` or `r.Validate` | Signed values come from `r.PathValue` or the query | `http-signed-urls-read-the-url` |
| `route.Get(` handlers that write or delete, signed routes included | `Post`, `Put`, `Patch` or `Delete`; for an emailed link, a GET page that posts back | `http-no-writes-on-get` |
| `go func` in handlers; closures given to `cache.Flexible` or `r.Background` that use `r` | `r.Background`/`task`, and the `ctx` they give | `run-background-not-go-func` |
| `httpclient.` calls without `EnsureSuccessful`; `.Retry(` on POST | Status checked; timeouts; a key the provider deduplicates | `run-http-client` |
| `time.Now(`; `==` on times read back; `.Format(` on stored times | `date.Now(ctx)`; `Equal`; `In(location)` | `run-time-and-clock` |
| Jobs without `JobOptions`; jobs that call `queue.Release` | `Tries`/`Backoff`, or `RetryFor` | `jobs-retries-are-opt-in` |
| `queue:"model"` fields on jobs that must not vanish | `FailWhenMissingModels` | `jobs-missing-models` |
| Workflow `Handle` methods: code outside `run.Do`/`run.Step`, `defer`, step names in loops | Side effects in steps; unique names | `jobs-workflow-replay` |
| `event.Dispatch(` whose error goes to `web.Fail`; `laravel.Listen` for mail or HTTP | `laravel.Report`; `laravel.ListenQueued` | `jobs-listener-errors` |
| Job types without `JobName`; `queue.Dispatch(ctx, &` | `JobName`; value dispatch | `jobs-stable-names` |
| `DailyAt`, `At`, `Between` in `commands/schedule.go`; one job type scheduled twice | UTC times; `Name` per task; a shared cache | `jobs-schedule-utc-names-and-locks` |
| `web.Abortf(500` / `web.Abort(5..` with error text; `Render` functions; `APP_DEBUG` in production | `web.Fail` with `%w`; `web.PublicMessage`; debug off | `ops-debug-and-error-messages` |
| `storage.Use("public")` for invoices, exports, documents | A private disk (`FILESYSTEM_DISK` not `public`) and an authorizing download handler | `ops-private-files` |
| Production `CACHE_STORE` | `database` or `redis` | `ops-shared-cache-store` |
| Deploy scripts, process-manager units, load balancer checks | Listen address, stop timeout, `migrate --force`, `queue:restart`, a readiness check | `ops-deploy-checklist` |
| Changes to `APP_KEY` | `APP_PREVIOUS_KEYS`, except for a leaked key | `ops-app-key-rotation` |
| `os.ReadFile("storage/`, `os.Open("public/` | `StoragePath` / `PublicPath` or the `storage` package | `ops-paths-from-base-path` |
| Build and deploy steps that copy `public/` | `npm run build` first; `public/hot` excluded; restart after a rebuild | `ops-frontend-assets` |
| `slog.Info(`, `log.Printf(`, `fmt.Sprintf` inside log messages | `slog.InfoContext(ctx, ..)` with fields; no secrets | `ops-logging-with-context` |
3. **Report each finding** with the file and line, what happens (with the status code or the data affected), the rule, and the fix from the rule's Correct example.
## How to Use the Rules
Read individual rule files for the explanation and examples:
```
rules/data-update-not-save.md
rules/auth-scope-nested-routes.md
rules/run-background-not-go-func.md
```
Each rule file contains:
- Why it matters, with quotes from the docs (and a few source comments) bundled with `go.laravel.com` v0.1.0
- The common version, as a complete Go file that compiles, and what it does (tested where noted)
- The version to write
## References
- [Laravel for Go](https://laravel.com/go)
- [Laravel for Go documentation](https://laravel.com/go/docs)
- [laravel/go skeleton](https://github.com/laravel/go)
- [laravel/go-framework](https://github.com/laravel/go-framework)
## Full Compiled Document
For the complete guide with all rules expanded: `AGENTS.md`
Files in this skill
- README.md
- SKILL.md
- rules/_sections.md
- rules/_template.md
- rules/arch-env-through-services.md
- rules/arch-services-hold-no-request-state.md
- rules/auth-exists-is-not-ownership.md
- rules/auth-guest-abilities.md
- rules/auth-login-email-and-throttle.md
- rules/auth-scope-nested-routes.md
- rules/auth-validate-runs-authorize.md
- rules/data-bulk-writes-skip-hooks.md
- rules/data-chunk-by-id-when-writing.md
- rules/data-default-columns-need-pointers.md
- rules/data-eager-load.md
- rules/data-group-or-conditions.md
- rules/data-nullable-columns-and-aggregates.md
- rules/data-pagination-keep-filters.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.