# Laravel Excellence Prover MCP for AI Agents AI Agent Connect

> Laravel Excellence Prover forces your AI agent to write production-ready Laravel code. It stops the agent from using "quick fixes" like manual validation or inline authorization, ensuring every line follows framework best practices. It catches N+1 queries, prevents fat controllers, and secures mass assignments automatically.

## Overview
- **Category:** productivity
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_xVT6WxKnn5P5RXCAVRvEGptio7bgnTnovi5pfdfY/ai-agent-connect
- **Tags:** laravel, php, code-quality, n-plus-one, structured-reasoning, decision-pivots, eloquent, agentic-pipeline

## Description

Laravel Excellence Prover is an Connector that ensures your AI agent writes high-quality, production-ready Laravel code. Writing Laravel with an AI agent often feels like a gamble. You'll get code that technically works but violates every principle a senior developer lives by. One minute it's fine, the next it's a performance disaster with N+1 queries or a security hole from a lazy call that passes all request data directly to a database model. This Connector changes that dynamic by acting as a rigorous code reviewer that won't let the agent ship subpar work. Instead of just trying to write good code, the agent has to prove its logic meets specific standards for query optimization, responsibility separation, and architectural integrity. It forces the AI to use framework-specific classes for validation and dedicated service classes for logic. When you use this through the Vinkius catalog, you're essentially giving your agent a senior mentor that demands idiomatic PHP. It catches the traps where an AI might claim to follow best practices while actually writing raw SQL or using configuration calls that break your cache. The result is a codebase that stays clean, scalable, and secure, regardless of how many features you're cranking out. It handles the heavy lifting of checking for proper use of transactions, typed properties, and API resources. You no longer have to worry about an AI skipping the database transaction or using env calls that break your production config. It ensures that every feature follows a strict pattern where controllers only handle the request and response, while the actual work happens in the background. This means your deployment cycle stays smooth because the code is already vetted for the most common senior-level mistakes.

## Tools

### validate_laravel_excellence
Checks a code snippet against best practices, performance standards, and architectural rules to ensure it is production ready.

## Prompt Examples

**Prompt:** 
```
I'm writing a store method for orders. I'll just use $request->all() to save it to the database and send an email.
```

**Response:** 
```
Verdict: FAT_CONTROLLER and Mass Assignment Unsafe.

Here is why this fails our excellence check:
* **Mass Assignment**: Using `$request->all()` allows users to inject fields like `is_admin` into your database.
* **Fat Controller**: You are handling validation, database logic, and email sending all in one place.

**Recommended Fix:**
1. Create a `StoreOrderRequest` to handle validation.
2. Create an `OrderAction` or `OrderService` to handle the database logic.
3. Dispatch an `OrderCreated` event to handle the email side effect.
```

**Prompt:** 
```
How should I list 50 products with their categories on a page?
```

**Response:** 
```
Verdict: N_PLUS_ONE_DETECTED.

If you loop through products and access `$product->category` in your Blade view, you will fire 50 separate database queries.

**Optimized Approach:**
Use eager loading in your controller:
`$products = Product::with('category')->paginate(50);`

This ensures only 2 queries are fired regardless of the number of products.
```

**Prompt:** 
```
Can you write a quick controller to handle a user update?
```

**Response:** 
```
Verdict: CODE_PROVEN.

Your request follows senior-level standards:
* **Route Model Binding**: Correctly identifies the user.
* **FormRequest**: Handles all input validation.
* **Service Class**: The `UserService` handles the logic.
* **Thin Controller**: The controller only manages the HTTP request and response.

This code is safe to ship.
```

## Capabilities

### Catch N+1 queries
Identifies lazy-loading issues in loops or Blade views before they hit production.

### Enforce idiomatic Laravel
Rejects manual workarounds in favor of built-in features like Policies and API Resources.

### Separate business logic
Moves heavy logic out of controllers and into dedicated Service or Action classes.

### Secure mass assignments
Ensures only whitelisted fields are saved to the database using validated input.

### Validate architecture
Checks for proper use of transactions, typed properties, and config files.

## Use Cases

### Fixing a bloated controller
A developer asks the agent to move 100 lines of logic into a Service class to keep the controller thin.

### Auditing an API endpoint
An engineer wants to ensure a new POST route is fully protected against mass assignment vulnerabilities.

### Optimizing a dashboard
A dev asks the agent to refactor a list view that is currently firing 50+ queries for a single page load.

### Setting up a new feature
A team wants to ensure a new user registration flow uses FormRequests and Events instead of manual logic.

## Benefits

- Eliminate N+1 queries: The tool catches lazy-loading issues in loops or Blade views before they hit production.
- Stop fat controllers: It forces the agent to move business logic into Service or Action classes, keeping your controllers thin.
- Prevent security leaks: By enforcing $request->validated() and explicit $fillable arrays, it closes mass assignment holes.
- Use native features: It rejects manual workarounds, ensuring you use FormRequests, Policies, and API Resources every time.
- Maintainable architecture: It checks for DB::transaction(), typed properties, and proper config() usage to keep the app scalable.

## How It Works

The bottom line is your AI agent stops guessing and starts writing production-grade Laravel code.

1. Provide a Laravel feature or code snippet to your AI client.
2. The agent calls the validation tool to check the code against the five pillars of excellence.
3. You get a verdict on the code quality with specific instructions on what to fix before shipping.

## Frequently Asked Questions

**What is the Laravel Excellence Prover MCP?**
It is a tool that acts as a senior Laravel mentor for your AI agent, ensuring it writes high-quality, production-ready code that follows best practices.

**How does it stop N+1 query issues?**
It scans your code for lazy-loading issues in loops or Blade views and forces the agent to use eager loading like with() instead.

**Can it help with security?**
Yes, it specifically checks for mass assignment vulnerabilities by ensuring your agent uses $request->validated() and explicit $fillable arrays.

**Does it make my AI write faster?**
It doesn't change the speed of the AI, but it significantly reduces the time you spend fixing bugs and refactoring messy code after the AI finishes.

**What happens if the AI writes a fat controller?**
The tool will flag it as a violation and tell the agent to move the business logic into a dedicated Service or Action class.

**Will it work with my existing Laravel app?**
Yes, you can use it to audit existing code or ensure that all new features added to your application meet your team's quality standards.

**Does Laravel Excellence Prover generate or write Laravel code?**
No. The agent writes the code. The tool VALIDATES that the code meets senior-level Laravel standards — query optimization, framework idioms, responsibility separation, mass assignment protection, and architectural compliance. It catches the five failure modes before the code is committed.

**What does it catch that a system prompt instruction doesn't?**
Prompt instructions are suggestions — agents routinely ignore 'use eager loading' or 'validate with FormRequests.' Tool calls are obligations — the agent must fill every field. The engine has 22 consistency rules that catch specific anti-patterns: N+1, raw SQL without justification, env() in app code, unbounded get()/all(), synchronous heavy I/O, dd()/dump() in production, magic values, vague claims like 'follows best practices', and platitude conclusions. A prompt cannot enforce these — a tool schema can.

**Why is N+1 checked before everything else?**
Because N+1 is the single most common and damaging performance anti-pattern in Laravel. A beautifully architected application with clean controllers and perfect FormRequests will still crash under load if every Blade view triggers 100 lazy-loaded queries. N+1 is checked first because no amount of clean architecture compensates for a database under siege.

**Can I use this for existing legacy Laravel codebases?**
Yes. When refactoring legacy code, call the tool to validate each change against excellence standards. The tool catches the same patterns regardless of whether you're writing new code or improving old code. Start with the most critical pivot: enable Model::preventLazyLoading() to surface all N+1 issues, then progressively extract logic from fat controllers into Services, add FormRequests, and define $fillable.