Skip to content
Back to skills

Writing Laravel Go Apps

ASecurity

Builds and refactors Laravel for Go application code using the installed framework's Markdown documentation, resource-oriented handlers, and idiomatic Laravel for Go patterns. Use when adding features, routes, handlers, models, migrations, validation, jobs, mail, events, scheduling, or any backend application code.

  • 3 stars
  • 0 votes
  • 1 copy
  • 2 views
  • Added December 3, 2026
developmentrustgophpsqlexpresstestingapidatabasebackendsecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add airshell/laravel-php-to-rust-go --skill writing-laravel-go-apps --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Writing Laravel Go Apps?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Writing Laravel Go Apps
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-writing-laravel-go-apps/badge)](https://www.skillsdirectory.com/skills/airshell-writing-laravel-go-apps)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: writing-laravel-go-apps
description: Builds and refactors Laravel for Go application code using the installed framework's Markdown documentation, resource-oriented handlers, and idiomatic Laravel for Go patterns. Use when adding features, routes, handlers, models, migrations, validation, jobs, mail, events, scheduling, or any backend application code.
---

# Writing Laravel for Go Applications

## 1. Consult the Installed Framework Docs

The `go.laravel.com` module bundles the complete Markdown documentation for the exact version this application depends on. Always check the relevant guide before using or changing a framework API—never guess from Laravel PHP or other Go frameworks.

Locate the docs directory for this project:

```sh
.agents/skills/writing-laravel-go-apps/scripts/docs-path.sh
```

Start with `<docs>/documentation.md` for the full table of contents, or open the guide you need directly:

| Topic | Guide |
| --- | --- |
| App layout, config, services, context | `structure.md`, `configuration.md`, `services.md`, `context.md` |
| Routing, handlers, middleware, requests, responses | `routing.md`, `handlers.md`, `middleware.md`, `requests.md`, `responses.md`, `urls.md` |
| Validation & errors | `validation.md`, `errors.md` |
| Models, relationships, factories, queries, migrations | `models.md`, `model-relationships.md`, `factories.md`, `queries.md`, `migrations.md`, `pagination.md` |
| Auth, authorization, verification, passwords | `authentication.md`, `authorization.md`, `verification.md`, `passwords.md` |
| Queues, events, mail, notifications, scheduling, workflows | `queues.md`, `events.md`, `mail.md`, `notifications.md`, `scheduling.md`, `workflows.md` |
| Cache, session, storage, HTTP client, rate limiting | `cache.md`, `session.md`, `filesystem.md`, `http-client.md`, `rate-limiting.md` |
| Inertia, views, head metadata, Vite | `inertia.md`, `views.md`, `head.md`, `vite.md` |
| Time, strings, console commands | `time.md`, `strings.md`, `console.md` |
| Testing | `testing.md` |

## 2. Code Philosophy & File Organization

Write idiomatic Go guided by Laravel's emphasis on clarity and developer ergonomics:

- Before writing code, check sibling files (nearby handlers, models, tests) and follow the application's established patterns rather than introducing a second way to do the same job.
- Name types with domain nouns, operations with verbs, and predicates with `Is`, `Has`, `Can`, or `Should` (`Published`, `SendWelcomeEmail`, `IsExpired`) rather than generic or abbreviated names (`Process`, `HandleData`, `Mgr`). Keep function names short when the package or receiver already supplies the context.
- Put high-level operations first, followed by the unexported helpers they call so files read top-down rather than alphabetically. Keep code in its owning domain and avoid catch-all `helpers`, `common`, or `utils` packages.
- Extract a helper function or method when its name clarifies the caller, isolates a meaningful policy or decision, removes real duplication, or marks a distinct boundary. Do not extract mechanically to hit a line limit, and keep ordered steps together when splitting them would hide sequencing or force passing a bundle of intermediate state—ask whether the caller becomes a clearer explanation or merely shorter.
- Prefer direct model queries, concrete types, and visible control flow over speculative abstractions. Use early-return guards and explicit error checks to keep the main path flat, keep explicit `if`/`switch` branches when they read clearer than dense expressions, and avoid repository interfaces or manager wrappers unless there is a real, immediate need.
- Use single blank lines like paragraphs to separate logical phases (setup, guards, main work, final return), keeping tightly related lines together and avoiding blank lines immediately inside blocks.
- Use comments sparingly—almost never. Let clear names and small functions explain the code; never write comments that narrate what a block does. When a rare `//` implementation comment is genuinely warranted for a non-obvious *why* (such as an external API quirk or subtle invariant), prefer a concise single line ending with `...`.
- Be disciplined about creating new folders and files—split a file or package when it holds distinct responsibilities, not when it crosses a line count, and remember Go doesn't require one type per file:
  - Keep a model's authorization abilities and model-specific enums right in the model's file (e.g., `models/post.go`) unless the project already uses a separate `policies/` package, and keep factories in `database/factories/`.
  - Group related events by domain in a single file; if an app only has a handful of events or listeners, keeping them in one `events` or `listeners` file is completely fine. Split into domain files only when a file actually grows large.
  - Stick to the skeleton's directory structure and organize neatly by domain; don't create unsolicited documentation files.

### Where Things Live

| Thing | Location |
| --- | --- |
| Routes & rate limiters | `routes/` (`web.go`, `api.go`, `channels.go`), or `bootstrap/app.go` for global rate limiters |
| Resource handlers | `handlers/` (one package per resource) |
| Reusable HTTP middleware | `middleware/` (alias the import if a file also imports `go.laravel.com/middleware`) |
| Custom validation rules | Inline with `rule.Func` or in the handler package if used once; `rules/` if reused |
| Models, policies & factories | `models/` (keep model-specific enums and policies in the model file, or `policies/` if used); `database/factories/` for factories |
| Reusable domain actions | `actions/` (group related actions by domain file, e.g., `actions/posts.go`, `actions/billing.go`) |
| Queued jobs & job middleware | `jobs/` |
| Workflows | `workflows/` |
| Mailables | `mails/` |
| Notifications | `notifications/` |
| Events & listeners | `events/` and `listeners/` |
| Feature flags | `features/` |
| Console commands & schedule | `commands/` (`commands/schedule.go` for the schedule) |
| Application service wiring | `services/services.go` |
| Shared value objects, enums, custom errors & custom drivers | `support/` (organized by domain when needed, e.g., `support/billing/`) |

## 3. Resource-Oriented, Lean Handlers

Organize `handlers/` by resource package, keeping each package focused on standard CRUD actions (whether routes are registered individually or in groups):

- `Index` — list resources
- `Create` — show creation form
- `Store` — validate and create a resource
- `Show` — display a single resource
- `Edit` — show edit form
- `Update` — validate and update a resource
- `Destroy` — delete a resource

### Extract Sub-Resources Instead of Custom Verbs

When an operation doesn't fit those seven actions, introduce a new resource package under `handlers/` instead of adding custom verbs like `Publish`, `Archive`, or `Resend` to an existing handler package. Follow Go's package naming convention: keep names all-lowercase with no underscores or mixed case, and prefer a shorter domain noun when it is unambiguous across the app (for example, `handlers/exports` when there is only one kind of export):

- Publishing a post → `handlers/publishedposts/publishedposts.go` (`Store`, `Destroy`)
- Archiving a project → `handlers/projectarchives/projectarchives.go` (`Store`, `Destroy`)
- Resending an invitation → `handlers/invitationresends/invitationresends.go` (`Store`)
- Exporting an invoice → `handlers/invoiceexports/invoiceexports.go` (`Store`, `Show`)

Keeping these packages flat under `handlers/` avoids import collisions and aliasing in `routes/web.go`, and keeps every handler package small, predictable, and easy to navigate.

### Keep Handlers Thin

A handler should read like a short summary of the HTTP exchange:

1. Read typed input from the request: body input via `r.Validate[NewPost]()` or `r.Bind[NewPost]()` (body only; never reads query parameters), query parameters via `r.Query[PostFilters]()` or `r.QueryInto(&filters)` (query string only; there are no untyped `r.Input`/`r.String`/`r.File` helpers), route models via `model.FromRoute[models.Post](r, "post")`, and the signed-in user via `models.CurrentUser(r)`.
2. Authorize via policies (`auth.Authorize(r, ...)`).
3. Perform the action—a model operation, a focused domain function/service via `services.From(r)`, or dispatching a job/event/mail.
4. Return the response—`inertia.Render(...)`, `web.Redirect(...)`, or `web.JSON(...)`, using `web.Fail(err)` or `web.Abort(status)` on failure.

Push reusable multi-step domain operations into plain functions in `actions/` (grouped by domain file, e.g., `actions/posts.go`, `actions/billing.go`), and push external API calls or slow side effects into jobs (`jobs/`) or services (`services/`) rather than growing handler bodies.

```go
package posts

import (
	"go.laravel.com/inertia"
	"go.laravel.com/model"
	"go.laravel.com/validation"
	"go.laravel.com/validation/rule"
	"go.laravel.com/web"

	"app/models"
)

type NewPost struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

func (f *NewPost) Rules() validation.Rules {
	return validation.For(f,
		rule.Field(&f.Title, rule.Required, rule.Max(255)),
		rule.Field(&f.Body, rule.Required),
	)
}

func Index(r *web.Request) *web.Response {
	posts, err := model.Query[models.Post]().Latest("created_at").Get(r)
	if err != nil {
		return web.Fail(err)
	}

	return inertia.Render("Posts/Index", inertia.Props{"posts": posts})
}

func Show(r *web.Request) *web.Response {
	post, err := model.FromRoute[models.Post](r, "post")
	if err != nil {
		return web.Fail(err)
	}

	return inertia.Render("Posts/Show", inertia.Props{"post": post})
}
```

### Action Functions

When a multi-step domain operation is reused across handlers, jobs, or commands—or would make a handler noisy—extract a plain function in `package actions`, grouping related operations by domain file (`actions/posts.go`, `actions/billing.go`). Keeping them in one flat `actions` package avoids package-name collisions with `handlers/<resource>` and local variables like `posts`. Take `context.Context` first and write a direct function rather than wrapping it in an empty struct:

```go
// actions/posts.go
package actions

import (
	"context"

	"go.laravel.com/date"
	"go.laravel.com/event"
	"go.laravel.com/model"

	"app/events"
	"app/models"
)

func PublishPost(ctx context.Context, post *models.Post) error {
	now := date.Now(ctx)
	post.PublishedAt = &now

	if err := model.Save(ctx, post); err != nil {
		return err
	}

	return event.Dispatch(ctx, events.PostPublished{PostID: post.ID})
}
```

Then call it cleanly from a handler, job, or command:

```go
func Store(r *web.Request) *web.Response {
	post, err := model.FromRoute[models.Post](r, "post")
	if err != nil {
		return web.Fail(err)
	}

	if err := actions.PublishPost(r, &post); err != nil {
		return web.Fail(err)
	}

	return web.RedirectRoute("posts.show", "post", &post)
}
```

## 4. Organizing Scheduled Work & Background Jobs

Keep scheduled task callbacks thin: point the scheduler in `commands/` at a job or a plain function/service method so the underlying logic can be invoked and tested directly without going through the scheduler.

## 5. Queries, Security & Framework Idioms

- Eager load relationships when displaying lists, use relationship counts (`WithCount`) instead of loading full relations just to count them, chunk large datasets, and always pair pagination with a deterministic `OrderBy` (including a unique tie-breaker like `id` when needed).
- Authentication is not authorization, and validation is not authorization—explicitly authorize protected actions via policies (prefer `404` over `403` when cross-tenant isolation shouldn't reveal whether a record exists). Never interpolate untrusted input into raw SQL (always bind parameters and allow-list user-chosen sort columns), and read environment variables in `services.New` / config rather than scattering env reads in handlers.
- Pass `context.Context` first to functions that do I/O or read the application scope. From handlers, pass `r` (which implements `context.Context`) rather than `*web.Request` into models, queries, and services.
- Handlers return `*web.Response` and fail with `web.Fail(err)` or `web.Abort(status)`. Code below handlers returns errors wrapped with `fmt.Errorf("...: %w", err)`.
- Always read the current time via `date.Now(ctx)` (not `time.Now()`) so tests can control time with `client.Travel(...)`.
- Add `json` tags on decoded structs (`encoding/json/v2` uses exact field matching).
- Wire routes, middleware, database drivers, migrations, seeders, commands, schedule, listeners, jobs, and services explicitly in `bootstrap/app.go` and `services/services.go`.

Files in this skill

  • SKILL.md12.5 KB
  • scripts/docs-path.sh72 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.