Introduction
When you start coding with AI tools like Claude, it’s tempting to just throw in prompts and copy paste whatever comes out. That works for small hacks, but if you’re a Laravel dev building production-grade apps, you need more discipline. The trick is to treat AI like a junior team member who follows your rules and guides.
This is where context engineering comes in: shaping the instructions and rules around the AI so that it consistently produces reliable, testable, maintainable code. Instead of reminding it every time "hey, write tests first" or "please follow PSR-12" you define guides up front. Think of them as your AI’s coding playbook.
Context Engineering: Rules Instead of Prompts
Context engineering isn’t just about describing what you want, it’s about systematizing it. A vague one-liner like "write a Laravel controller for products" will give you boilerplate that may or may not be useful. But if you include rules like:
Rules for all code you generate:
- Always target Laravel 10
- Follow PSR-12 coding standards
- Include type hints and return types
- Add PHPUnit tests for every class
- Use dependency injection where possible
Suddenly, the AI behaves more predictably. You don’t need to repeat “write tests” every time; the guide itself keeps it in line.
Tip:
If you are a Laravel developer, you can use https://pestphp.com/ framework instead of PHPUnit
For example, when you say:
"Build a ProductService class with methods to add and update products."
The AI already knows: PSR-12 + PHPUnit tests + DI + Laravel 10. That’s context engineering at work.
Developing with TDD: A Rule, Not a Prompt
Instead of prompting “write tests first,” you bake TDD into the AI’s rulebook. This is powerful because TDD becomes a consistent approach, not a one-off instruction.
Here’s a practical rule set you might keep in your AI coding sessions:
Testing Rules:
- Always write functional and unit tests first before the implementation
- Tests must use PHPUnit (latest version supported by Laravel 10)
- Cover edge cases (null input, invalid data, permission denied)
- Implementation must satisfy all tests
So if you ask:
“Generate a SlugService that turns titles into URL-safe slugs.”
The AI, guided by rules, will first produce PHPUnit tests like:
public function testSlugifyBasicString(): void {
$slug = (new SlugService())->slugify("Hello World");
$this->assertSame("hello-world", $slug);
}
public function testSlugifyHandlesAccents(): void {
$slug = (new SlugService())->slugify("Crème Brûlée");
$this->assertSame("creme-brulee", $slug);
}
Then it generates the actual service so those tests pass. That’s TDD baked into the workflow not because you told it in the prompt, but because it’s in the rules.
Using MCP For Laravel
One of the biggest bottlenecks with AI coding is that the model doesn’t actually know your project. It just guesses. That’s where MCP (Model Context Protocol) comes in. MCP is like giving your AI a USB-C port into your app, it can pull in real files, database schemas, and project tools instead of hallucinating. Now when you ask, “write me a ProductController,” it can actually use your real products table, your existing FormRequests, and your policies. It’s context-driven coding.
On top of that, there’s Laravel Boost, which is basically an MCP server built specifically for Laravel. Install it in your app and suddenly your AI can “see” your routes, models, migrations, configs basically the Laravel specific guts of your project. Instead of spitting out generic boilerplate, the AI generates code that actually matches your stack. Think controllers that use your validation classes, migrations that line up with your schema, and policies that plug into your roles.
And then there’s Playwright, which ties the loop together. It gives you fast, reliable e2e browser tests that you can run against whatever the AI generates. So even if the model writes a controller or a Vue component for you, you don’t have to just “trust” it, you throw Playwright tests at it and see if it actually works. Failures turn into feedback for the AI, and you’re iterating with real safety nets.
Put all three together MCP for awareness, Laravel Boost for Laravel-native context, and Playwright for end-to-end validation and you get the sweet spot: faster scaffolding with fewer bugs. Instead of fixing AI’s bad guesses, you spend your time building features and letting the tests keep everything honest.
One of the coolest things about combining MCP (Model Context Protocol) with Laravel Boost and Playwright is that it takes the AI out of guesswork mode and drops it right into your actual project context. Instead of hallucinating table columns or validation rules, the model can pull in your real migrations, request classes, and policies. Add Playwright on top, and you’ve got instant end-to-end validation.
composer require laravel/boost
php artisan boost:install
php artisan boost:serve
Now your AI client (Claude, Cursor, etc.) can query your Laravel app directly. It knows your routes, migrations, configs, even ecosystem docs for packages like Livewire or Inertia. Pair that with Playwright for browser-level testing:
npm init -y
npm i -D @playwright/test
npx playwright install
When you bring Playwright into the mix, don’t just think of it as “another testing framework.” In this setup, Playwright is more like the eyes of the LLM. It’s how the AI (and you) can observe whether the code it scaffolded actually behaves as intended in a real browser environment.
Suddenly you’ve got a full stack that scaffolds code and tests it automatically.
To a human dev, this looks like a test. To the AI, this is ground truth feedback. If the table doesn’t contain “Test Product,” something in its generated controller, route, or view was off. That feedback goes back into the loop: the AI adjusts its code, re-runs, and verifies again.
So Playwright isn’t just validating it’s closing the sensory gap for the LLM. With MCP providing the context and Boost grounding the AI in Laravel conventions, Playwright gives it a way to “see” whether the system it just built actually functions. That’s what turns AI coding from educated guessing into iterative, verifiable development.
Final Thoughts
AI coding is no longer about tossing random prompts into a black box and hoping for the best. With context engineering, MCP, Laravel Boost, and Playwright, we can actually bring discipline and reliability into the mix.
MCP makes sure the AI isn’t guessing—it’s working with your real project context. Laravel Boost sharpens that further by giving the model Laravel-native awareness, so its scaffolding feels like code you’d actually write yourself. And Playwright? That’s the eyes of the system, validating what’s been built in a real browser so you’re not shipping broken assumptions.
Add to that a rules-first mindset—TDD principles, coding standards, test coverage goals—and suddenly you’re not just experimenting with AI, you’re building faster and safer. Instead of fighting bad output, you spend more time on the interesting part: crafting features and solving problems.
The takeaway is simple: AI isn’t here to replace developers, it’s here to amplify us. If we give it context, rules, and feedback loops, it becomes a true collaborator. That’s how we move from flashy demos to bug-free, production-ready AI-assisted development.