These 14 Laravel prompts help ChatGPT, Claude, Claude Code and Codex write Laravel code that holds up: Eloquent without N+1 queries, Form Requests and policies, queued jobs that retry safely, Pest feature tests, upgrades to Laravel 13, and Artisan commands built with the Laravel Prompts package. Each prompt is a template with blanks you fill in.
If you searched for Laravel Prompts the package, the official Laravel Prompts docs describe it as "a PHP package for adding beautiful and user-friendly forms to your command-line applications." Prompts 8 to 10 below help you build and test commands with it.
How to use these prompts
Copy a prompt, replace each blank in double braces, or keep the default after the colon. {{laravel_version:13}} means Laravel 13 unless you change it.
State your versions. Laravel's release notes list Laravel 13 as released on 17 March 2026, requiring PHP 8.3 or later, with security fixes until 17 March 2028. Laravel 12's bug fixes ended on 13 August 2026, and it gets security fixes until 24 February 2027. Version 13 also adds PHP attributes like #[Middleware], #[Authorize] and #[Tries], so a model that doesn't know your version may mix old and new styles.
Paste the model with the code that uses it. A controller alone hides the relationships that cause extra queries. Mention your stack too: Blade, Livewire or Inertia, Pest or PHPUnit, and which queue driver you use.
In an agent, let it run php artisan test and your formatter after each change. If you use Claude Code, Codex or Cursor, Laravel Boost gives the agent Laravel guidelines and an MCP server with tools such as database schema and log reading.
How do you write Eloquent code that stays fast?
1. Find and fix N+1 queries
The Eloquent relationships docs show a loop over 25 books running 26 queries, and with() reducing it to two. They also show Model::preventLazyLoading() for catching lazy loads outside production.
This page runs {{count:180}} queries. Here are the models, the controller
and the Blade view:
{{code}}
Find every N+1 pattern. Fix it with with() (including nested and
constrained eager loads), withCount() or withSum() for aggregates, and
loadMissing() where the relation is only sometimes needed. Then add
Model::preventLazyLoading(! $this->app->isProduction()) to
AppServiceProvider and tell me which other code paths are likely to
start throwing. Add a test that fails if the query count grows.
2. Design models and migrations from a spec
Get keys, indexes and casts right before data exists.
Design the Laravel {{laravel_version:13}} models and migrations for:
{{spec}}
For each table: columns with types, foreign keys with constrained() and
an onDelete choice explained, unique and composite indexes for the
queries in the spec, and timestamps or soft deletes only where needed.
For each model: relationships with return types, casts (including enums
and dates), and fillable or guarded with a reason. Add a factory for
each model. Show the files, then list the queries you expect and which
index serves each.
How do you handle validation, authorization and APIs?
3. Slim down a fat controller
Move validation into a Form Request (php artisan make:request) and business logic into a class you can test alone.
This controller method does too much:
{{controller}}
Refactor it: move validation and authorization into a Form Request,
read only $request->validated() in the controller, and move business
logic into a single-purpose action class with a handle method. Wrap
multi-step writes in a database transaction. Keep routes and responses
the same. Show each file and a feature test that covers a valid
request, a validation failure and an unauthorized user.
4. Write a policy and wire it up
Laravel discovers policies automatically when they follow its naming conventions, and Laravel 13 lets you declare checks with the #[Authorize] attribute on controller methods.
Write a Laravel policy for {{model:Project}} with these rules:
{{rules}}
Generate it with php artisan make:policy, cover viewAny, view,
create, update, delete and any custom ability the rules need, and add a
before method only if admins truly bypass everything. Show how to apply
it in the controller with {{style:the #[Authorize] attribute}}, in
Blade with @can, and in a Form Request. Add tests for each ability with
an owner, a teammate and a stranger.
5. Build an API response with resources
Laravel 13 ships JsonApiResource for responses that follow the JSON:API specification, generated with php artisan make:resource PostResource --json-api.
Build the API response for GET {{endpoint:/api/projects}} in Laravel
{{laravel_version:13}}.
Model and relationships:
{{models}}
Use {{format:a standard JsonResource}} (or JsonApiResource if I say
JSON:API). Decide which fields to expose and which to hide, include
relationships only when eager loaded, paginate the collection, and add
filtering by {{filters:status and owner}}. Show the resource, the
controller method and a feature test that checks the JSON structure and
the query count.
How do you build queued jobs that don't break?
6. Move slow work into a queued job
The queues docs cover ShouldQueue, ShouldBeUnique, dispatching with afterCommit(), and Laravel 13 attributes such as #[Tries], #[Backoff] and #[Timeout].
This request {{work:generates a PDF and emails it}} and takes several
seconds:
{{code}}
Move the work into a queued job. Pass model IDs or models with
SerializesModels, not large payloads. Dispatch with afterCommit() so the
job never runs before the data is saved. Set tries, backoff and timeout
with attributes, make the job idempotent so a retry can't send two
emails, and use ShouldBeUnique if duplicates are possible. Add a failed
method and a test with Queue::fake().
7. Debug jobs that run twice or get stuck
The queues docs say the worker --timeout value should always be at least several seconds shorter than the connection's retry_after value, or a frozen job may be retried while still running.
Our queued job {{job:SyncInvoices}} sometimes runs twice and sometimes
ends up in failed_jobs with a timeout.
Job class, config/queue.php connection and worker command:
{{code}}
Recent failed_jobs exception:
{{exception}}
Explain the likely causes, checking: retry_after compared with the
worker --timeout, the job's own timeout and tries, long external calls
without timeouts, and missing idempotency. Give the config and code
changes, and how to confirm the fix in staging.
How do you build Artisan commands with Laravel Prompts?
8. Build an interactive Artisan command
Laravel Prompts provides functions such as text, select, search, confirm, spin and progress, and each input can be validated with a closure or Laravel validation rules.
Build an Artisan command {{signature:users:invite}} for Laravel
{{laravel_version:13}} using Laravel Prompts.
What it should do:
{{behavior}}
Use the right prompt for each input: text with validation, select or
search for picking a record, multiselect for roles, confirm before
writing, spin for slow API calls and progress for loops. Validate with
Laravel rules where possible. Keep the handle method thin and call a
service class for the real work. Show the command class and an example
session.
9. Prompt only for missing arguments
The Artisan docs describe the PromptsForMissingInput interface, which asks for required arguments the user didn't pass, and promptForMissingArgumentsUsing() to customize the questions.
This Artisan command takes arguments and also needs to run in CI and
cron without a terminal:
{{command}}
Make it implement PromptsForMissingInput so a person running it by hand
is asked for missing arguments, with custom questions and a search
prompt for {{argument:the user}} in promptForMissingArgumentsUsing().
Make sure it never blocks waiting for input when run with
--no-interaction, and fails with a clear message instead. Show the class
and both ways to run it.
10. Test a command that uses Laravel Prompts
Laravel's console tests mock input with expectsQuestion, and expectsSearch for search and multisearch prompts. The Prompts docs add assertions like expectsPromptsInfo and expectsPromptsTable.
Write {{runner:Pest}} tests for this Artisan command that uses Laravel
Prompts:
{{command}}
Use $this->artisan() with expectsQuestion, expectsConfirmation,
expectsSearch and expectsPromptsTable where they apply, and assert the
exit code. Cover: the happy path, invalid input that triggers a
validation message, the user declining the confirm step, and running
with all arguments passed so no prompts appear. Use factories and
RefreshDatabase for data.
How do you test a Laravel app?
11. Write feature tests
The testing docs say Pest and PHPUnit are both supported out of the box and that "most of your tests should be feature tests."
Write {{runner:Pest}} feature tests for this Laravel feature:
{{routes_and_controller}}
Use RefreshDatabase and model factories, authenticate with actingAs, and
assert status codes, redirects, JSON or view data, and database state
with assertDatabaseHas. Cover the happy path, validation errors, an
unauthorized user, and one edge case from the code. Fake mail, queues
and HTTP calls to outside services. Name each test after the behavior
it checks.
12. Speed up a slow test suite
The testing docs describe php artisan test --parallel (with the brianium/paratest package), --profile to list the ten slowest tests, and the WithCachedConfig trait.
Our Laravel test suite takes {{time:9 minutes}}. Here is the output of
php artisan test --profile and our phpunit.xml:
{{output}}
Rank the fixes by time saved: running in parallel, caching config with
WithCachedConfig, replacing seeders with focused factories, moving
tests that don't need the framework to unit tests, faking slow HTTP
calls, and using an in-memory or faster database where it's safe.
Flag tests that will break when run in parallel and why.
How do you upgrade Laravel and set up AI tools?
13. Plan an upgrade to Laravel 13
The Laravel 13 upgrade guide gives an estimated upgrade time of 10 minutes and lists updating dependencies and request forgery protection as high-impact changes.
Plan an upgrade from Laravel {{from:12}} to 13. Here is composer.json,
bootstrap/app.php and our PHP version:
{{files}}
List: the PHP and package versions required (Laravel 13 needs PHP 8.3),
the changes from the upgrade guide that affect code like ours ordered
by impact, third-party packages that need new major versions, and
anything around the new PreventRequestForgery middleware we should
test. Give a step-by-step plan with the tests to run after each step,
and mark anything you're unsure applies.
14. Write custom AI guidelines for your app
Laravel Boost adds .md or .blade.php files you put in .ai/guidelines/ to its own Laravel guidelines when you run boost:install.
Read these parts of our Laravel app:
{{files}}
Write a short custom guideline file for AI coding agents working on it.
Cover only conventions specific to us that an agent can't infer from
Laravel defaults: where business logic lives, naming, how we handle
money and time zones, which packages to use for what, and test rules.
Use short imperative bullets, one example per rule where it helps, and
under 60 lines. List any conventions that look inconsistent in the code
so we can decide on one.
Turn your favorite one into a skill
If you run the N+1 or queued job prompt on every feature, make it a skill so Claude Code or Codex applies it when the task matches. Paste the prompt into the free SKILL.md generator to get a valid SKILL.md in your browser. For endpoints, the API testing prompts cover contract and edge-case tests in any stack, and the SQL prompts help when a query needs work below Eloquent.
To keep these prompts one shortcut away, save them in Kipt. Your prompts live as Markdown in a private GitHub repo you own, blanks like {{laravel_version:13}} stay fillable, and Cmd+K finds any prompt by name or tag.