Skip to content
Back to skills

Validation And Input

ASecurity

Validates request bodies, query strings, forms, uploads, and custom rules in Laravel for Go. Use when defining input or query structs, validating requests, handling PATCH updates, or writing custom validation rules.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgoapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add airshell/laravel-php-to-rust-go --skill validation-and-input --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Validation And Input?

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

Security grade badge for Validation And Input
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-validation-and-input-laravel-php-to-rust-go/badge)](https://www.skillsdirectory.com/skills/airshell-validation-and-input-laravel-php-to-rust-go)

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: validation-and-input
description: Validates request bodies, query strings, forms, uploads, and custom rules in Laravel for Go. Use when defining input or query structs, validating requests, handling PATCH updates, or writing custom validation rules.
---

# Validation & Typed Request Input

Consult `<docs>/validation.md` and `<docs>/requests.md` (locate via `.agents/skills/writing-laravel-go-apps/scripts/docs-path.sh`) for the full rule catalog, nested/list validation, custom messages, and custom rule APIs.

## Core Rules & Footguns

- Always read request input through typed structs with `json` tags—there are no untyped `r.Input`, `r.String`, or `r.File` helpers.
- Body input and query strings are strictly separated. `r.Validate[T]()` and `r.Bind[T]()` read only the request body; `r.Query[T]()` and `r.QueryInto(&filters)` read only the query string.
- Define rules on a pointer receiver `func (f *StorePost) Rules() validation.Rules` using `validation.For(f, rule.Field(&f.Title, ...), ...)` so misspelled field names fail to compile. Use `model.Unique[models.Post]()` and `model.Exists[models.Post]()` for database checks.
- You do not need type rules like `string` or `integer` because the Go field types enforce them automatically.
- Pass the error returned by `r.Validate[T]()` directly to `web.Fail(err)`—Laravel redirects web and Inertia forms back with errors and returns a `422` JSON response to API clients.
- Never validate directly into a model struct (`r.Validate[models.Post]()`); always validate into a dedicated input struct and copy the allowed fields into the model to prevent mass assignment.
- Use pointer fields (`*string`) for nullable fields (empty text inputs are trimmed and converted to `null` by default middleware). Use `validation.Sometimes[T]` for `PATCH` or partial-update forms where a missing field means "keep current value" and `null` means "clear it".
- Use `numeric.Decimal` (never `float64`) for money and exact decimal values.
- Use `validation.Validate(ctx, &input)` when validating a struct outside an HTTP request (such as in an action, job, or command).
- Keep one-off custom rules inline with `rule.Func(...)` or in the handler package; place reusable rules in `rules/`.

```go
package posts

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

	"app/models"
)

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

func (f *StorePost) Rules() validation.Rules {
	return validation.For(f,
		rule.Field(&f.Title, rule.Required, rule.Max(255), model.Unique[models.Post]()),
		rule.Field(&f.Body, rule.Required),
	)
}

func Store(r *web.Request) *web.Response {
	form, err := r.Validate[StorePost]()
	if err != nil {
		return web.Fail(err)
	}

	post := models.Post{Title: form.Title, Body: form.Body}
	if err := model.Create(r, &post); err != nil {
		return web.Fail(err)
	}

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

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.