Who it is forA Laravel developer who accepts reviews, comments or messages from users and wants a moderation check on the server.
The problemFree-text fields let in insults, spam and threats, and reviewing every submission by hand does not scale.
The outcomeForm submissions that answer yes to the moderation question fail validation with a friendly message, and the others pass.
What you need first
- PHP 8.4+ and Composer
- A PSR-18 HTTP client such as Guzzle or Symfony HttpClient
- Docker, to run laya-serve from the repo's compose.yaml
- Laravel 13+ for the Laravel steps (service provider, artisan commands, validation rule, cast)
Steps
- Run
composer require marcreichel/laya-phpin your Laravel app. - Start laya-serve with
docker compose up -d --waitfrom a clone of this repo and confirm it withphp artisan laya:health. - Add
Decides::not('Does the text contain insults, hate speech or threats?')to the rule list for the text field in your$request->validate()call. - Set your own
validation.layamessage if the default one does not fit your app. - Test the form with
Laya::fake(['answer' => true])so the rule fails without a running server. (inferred, check the README)
Prompt for your agent
In the marcreichel/laya-php repo's Laravel setup, add a Decides::not rule with the question <moderation question> to the <form field> validation in <controller or form request>. Report which test inputs pass and fail, and verify that a request with a fake answer of true is rejected.
Caveat. If laya-serve is unreachable or busy, the rule fails validation unless you add passWhenUnavailable(), so plan for that case.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for marcreichel/laya-php and "Block abusive or spam text in Laravel form submissions"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer