Install
$ agentstack add skill-iserter-laravel-claude-agents-laravel-validation-patterns ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Laravel Validation Patterns
Form Request Classes (Standard Approach)
user()->can('create', Order::class);
}
public function rules(): array
{
return [
'customer_id' => ['required', 'exists:customers,id'],
'items' => ['required', 'array', 'min:1'],
'items.*.product_id' => ['required', 'exists:products,id'],
'items.*.quantity' => ['required', 'integer', 'min:1'],
'notes' => ['nullable', 'string', 'max:500'],
];
}
public function messages(): array
{
return [
'items.required' => 'At least one item is required.',
'items.*.product_id.exists' => 'Product #:position does not exist.',
];
}
protected function prepareForValidation(): void
{
$this->merge([
'notes' => strip_tags($this->notes),
'email' => strtolower($this->email),
]);
}
public function after(): array
{
return [
function (\Illuminate\Validation\Validator $validator) {
if ($this->hasExceededOrderLimit()) {
$validator->errors()->add('items', 'You have exceeded the daily order limit.');
}
},
];
}
}
Custom Rule Objects
['required', 'string', 'min:8', new StrongPassword],
Conditional Validation
public function rules(): array
{
return [
'type' => ['required', Rule::in(['individual', 'company'])],
// Required only when type is company
'company_name' => ['required_if:type,company', 'string', 'max:255'],
// Excluded when type is individual (not present in validated data)
'tax_id' => ['exclude_if:type,individual', 'required', 'string'],
// Dynamic conditional rule
'billing_address' => [
Rule::when($this->boolean('different_billing'), ['required', 'string']),
],
// Conditional with sometimes (only validates if field is present)
'coupon_code' => ['sometimes', 'string', 'exists:coupons,code'],
];
}
Array and Nested Validation
public function rules(): array
{
return [
'tags' => ['required', 'array', 'min:1', 'max:10'],
'tags.*' => ['string', 'max:50'],
'items' => ['required', 'array'],
'items.*.name' => ['required', 'string'],
'items.*.options' => ['sometimes', 'array'],
'items.*.options.*.key' => ['required_with:items.*.options', 'string'],
];
}
Database Rules
public function rules(): array
{
return [
// Unique with ignore (for updates)
'email' => [
'required',
'email',
Rule::unique('users')->ignore($this->user()),
],
// Unique with scoping
'slug' => [
'required',
Rule::unique('posts')->where('tenant_id', $this->user()->tenant_id),
],
// Exists with additional constraints
'category_id' => [
'required',
Rule::exists('categories', 'id')->where('active', true),
],
];
}
Enum Validation
use App\Enums\OrderStatus;
public function rules(): array
{
return [
'status' => ['required', Rule::enum(OrderStatus::class)],
// Only allow specific enum values
'priority' => [
'required',
Rule::enum(Priority::class)->only([Priority::High, Priority::Critical]),
],
];
}
Working with Validated Data
// In controller
public function store(StoreOrderRequest $request)
{
// ✅ Use validated data only
$validated = $request->validated();
// ✅ Use safe() for partial access
$orderData = $request->safe()->only(['customer_id', 'notes']);
$items = $request->safe()->except(['notes']);
// ✅ Merge additional trusted data
$order = Order::create(
$request->safe()->merge(['user_id' => $request->user()->id])->all()
);
// ❌ Never use unvalidated input
$order = Order::create($request->all());
// ❌ Never bypass validation
$order = Order::create($request->input());
}
Common Pitfalls
// ❌ Validating inline in controllers
public function store(Request $request)
{
$request->validate(['title' => 'required']);
// Hard to test, not reusable
}
// ✅ Use Form Request classes
public function store(StorePostRequest $request)
{
Post::create($request->validated());
}
// ❌ Missing bail - continues validating after first failure
'email' => ['email', 'unique:users', 'dns_check'],
// ✅ Use bail to stop on first failure
'email' => ['bail', 'email', 'unique:users'],
// ❌ Using $request->all() instead of validated data
Order::create($request->all());
// ✅ Only validated and safe data
Order::create($request->validated());
Checklist
- [ ] Validation logic lives in Form Request classes, not controllers
- [ ] authorize() method properly checks permissions
- [ ] Custom Rule objects used for reusable complex validation
- [ ] prepareForValidation() sanitizes input before validation
- [ ] after() used for cross-field or business logic validation
- [ ] Array and nested fields validated with wildcard notation
- [ ] Database rules use proper scoping and ignore patterns
- [ ] Only validated/safe data used when creating or updating models
- [ ] bail used where early termination is desired
- [ ] Custom error messages provided for user-facing fields
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: iSerter
- Source: iSerter/laravel-claude-agents
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.