一键导入
laravel-debugging-prompts
// Create effective debugging prompts—include error messages, stack traces, expected vs actual behavior, logs, and attempted solutions
// Create effective debugging prompts—include error messages, stack traces, expected vs actual behavior, logs, and attempted solutions
Request effective code reviews—specify focus areas, provide context, ask for architectural feedback, reference Laravel conventions
Provide comprehensive context in prompts—files, errors, Laravel version, dependencies, and monorepo details—for accurate AI responses
Refine AI-generated code through specific feedback—point out errors, identify gaps, show desired changes, reference style guides
Use Laravel-specific vocabulary—Eloquent patterns, Form Requests, API resources, jobs/queues—to get idiomatic framework code
Structure prompts for clarity—separate concerns, prioritize requests, specify acceptance criteria, and break work into testable increments
Define clear constraints—performance, security, testing, architecture, dependencies—so AI generates code that meets your project standards
| name | laravel:debugging-prompts |
| description | Create effective debugging prompts—include error messages, stack traces, expected vs actual behavior, logs, and attempted solutions |
Debugging with AI requires complete information. Missing context means generic suggestions that don't solve your specific problem.
"Getting an error in the payment controller"
"Getting error when processing payment:
Error:
Illuminate\Database\QueryException: SQLSTATE[23000]:
Integrity constraint violation: 1452 Cannot add or update a child row:
a foreign key constraint fails (`app`.`payments`, CONSTRAINT `payments_order_id_foreign`
FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE)
Stack trace:
#0 app/Services/PaymentService.php(45): Payment::create()
#1 app/Http/Controllers/PaymentController.php(28): PaymentService->process()
#2 vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54)
Context:
['order_id' => 999, 'amount' => 5000, 'status' => 'pending']Why it works: Complete error, stack trace, context, and the specific data causing the issue.
"The API isn't returning the right data"
"Product API returning incorrect data:
Expected behavior:
{
"data": {
"id": 1,
"name": "Widget",
"price": "29.99",
"category": {
"id": 5,
"name": "Tools"
}
}
}
Actual behavior:
{
"data": {
"id": 1,
"name": "Widget",
"price": 2999,
"category": null
}
}
Issues:
Code:
// ProductController@show
return new ProductResource($product);
Product has category_id = 5 in database, but relationship not loading."
Why it works: Shows exact expected vs actual output, identifies specific issues, includes relevant code.
"Something's wrong with the queue"
"Job failing in queue:
Log entries:
[2024-01-15 10:30:15] local.ERROR: Job failed: ProcessOrderJob
{"order_id":123,"exception":"Stripe\\Exception\\InvalidRequestException:
No such customer: cus_invalid","attempts":3}
[2024-01-15 10:30:15] local.INFO: Order state before job
{"id":123,"status":"pending","stripe_customer_id":"cus_invalid"}
Job code:
public function handle()
{
$customer = $this->stripe->customers->retrieve(
$this->order->stripe_customer_id
);
// ...
}
State:
stripe_customer_id = "cus_invalid"Why it works: Includes logs, state information, relevant code, and context about retries.
"I think it's a caching issue"
"Suspect Redis cache is stale:
Hypothesis: Product prices are cached but not invalidating on update.
Evidence:
UPDATE products SET price = 3999 WHERE id = 1SELECT price FROM products WHERE id = 1 → 3999GET /api/products/1 → "price": "29.99"php artisan cache:clear, API returns correct price: "price": "39.99"Caching code:
public function show(Product $product)
{
$cached = Cache::remember("product.{$product->id}", 3600, function () use ($product) {
return new ProductResource($product);
});
return $cached;
}
Problem: Cache key doesn't invalidate when product updates. Need cache invalidation in ProductObserver or remove caching from show method."
Why it works: Clear hypothesis, concrete evidence, relevant code, proposed solution.
"I tried some things but nothing worked"
"Attempted solutions and results:
Attempt 1: Added eager loading
$products = Product::with('category')->get();
Result: Still getting N+1 queries. Debugbar shows 101 queries (1 for products, 100 for categories).
Attempt 2: Used load() after fetching
$products = Product::all();
$products->load('category');
Result: Same issue, still 101 queries.
Attempt 3: Checked relationship definition
// In Product model
public function category()
{
return $this->belongsTo(Category::class);
}
Result: Relationship looks correct. Foreign key category_id exists in products table.
Current state: Eager loading syntax seems correct but not working. Using Laravel 11.x. What am I missing?"
Why it works: Shows what was tried, exact code used, results observed, helps avoid suggesting already-tried solutions.
**Error:** [Full error message]
**Stack trace:** [Complete stack trace]
**File/Line:** [Where error occurs]
**Context:** [Laravel version, packages, environment]
**Data:** [Input data causing error]
**Expected:** [What should happen]
**Expected:** [Describe expected behavior with example]
**Actual:** [Describe actual behavior with example]
**Code:** [Relevant code snippet]
**State:** [Database state, variable values]
**Environment:** [Laravel version, Sail/host, packages]
**Problem:** [Describe slow operation]
**Metrics:** [Response time, query count, memory usage]
**Query log:** [Slow queries from Debugbar/Telescope]
**Code:** [Code causing performance issue]
**Dataset size:** [Number of records involved]
**Attempted:** [Optimizations already tried]
Debug effectively with AI:
More information = faster solutions. When debugging, over-communicate.