@mohammadhprp/system-prompt 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/bin/system-prompt.js +8 -0
- package/framework/README.md +163 -0
- package/framework/agents/README.md +49 -0
- package/framework/agents/backend-architect.md +146 -0
- package/framework/agents/researcher.md +79 -0
- package/framework/agents/reviewer.md +183 -0
- package/framework/agents/security-auditor.md +131 -0
- package/framework/commands/README.md +43 -0
- package/framework/commands/changelog.md +44 -0
- package/framework/commands/commit.md +31 -0
- package/framework/commands/learn.md +24 -0
- package/framework/commands/mr.md +46 -0
- package/framework/commands/pr.md +39 -0
- package/framework/commands/release.md +34 -0
- package/framework/commands/review.md +24 -0
- package/framework/commands/summarize-changes.md +49 -0
- package/framework/mcps/README.md +78 -0
- package/framework/mcps/excalidraw/README.md +37 -0
- package/framework/mcps/excalidraw/capabilities.md +54 -0
- package/framework/mcps/excalidraw/configs/opencode.json +8 -0
- package/framework/mcps/excalidraw/install.md +92 -0
- package/framework/mcps/excalidraw/troubleshooting.md +67 -0
- package/framework/mcps/figma-mcp-go/README.md +51 -0
- package/framework/mcps/figma-mcp-go/capabilities.md +190 -0
- package/framework/mcps/figma-mcp-go/configs/opencode.json +9 -0
- package/framework/mcps/figma-mcp-go/install.md +74 -0
- package/framework/mcps/figma-mcp-go/troubleshooting.md +99 -0
- package/framework/mcps/github-mcp/README.md +51 -0
- package/framework/mcps/github-mcp/capabilities.md +83 -0
- package/framework/mcps/github-mcp/configs/.env.example +1 -0
- package/framework/mcps/github-mcp/configs/opencode.json +13 -0
- package/framework/mcps/github-mcp/install.md +60 -0
- package/framework/mcps/github-mcp/troubleshooting.md +79 -0
- package/framework/mcps/gitlab-mcp/README.md +54 -0
- package/framework/mcps/gitlab-mcp/capabilities.md +216 -0
- package/framework/mcps/gitlab-mcp/configs/.env.example +2 -0
- package/framework/mcps/gitlab-mcp/configs/opencode.json +13 -0
- package/framework/mcps/gitlab-mcp/install.md +99 -0
- package/framework/mcps/gitlab-mcp/troubleshooting.md +116 -0
- package/framework/mcps/jira-mcp/README.md +53 -0
- package/framework/mcps/jira-mcp/capabilities.md +79 -0
- package/framework/mcps/jira-mcp/configs/.env.example +2 -0
- package/framework/mcps/jira-mcp/configs/opencode.json +13 -0
- package/framework/mcps/jira-mcp/install.md +94 -0
- package/framework/mcps/jira-mcp/troubleshooting.md +113 -0
- package/framework/mcps/laravel-boost/README.md +53 -0
- package/framework/mcps/laravel-boost/capabilities.md +92 -0
- package/framework/mcps/laravel-boost/configs/opencode.json +9 -0
- package/framework/mcps/laravel-boost/install.md +106 -0
- package/framework/mcps/laravel-boost/troubleshooting.md +119 -0
- package/framework/mcps/notion-mcp/README.md +58 -0
- package/framework/mcps/notion-mcp/capabilities.md +118 -0
- package/framework/mcps/notion-mcp/configs/opencode.json +9 -0
- package/framework/mcps/notion-mcp/install.md +70 -0
- package/framework/mcps/notion-mcp/troubleshooting.md +95 -0
- package/framework/mcps/playwright-mcp/README.md +50 -0
- package/framework/mcps/playwright-mcp/capabilities.md +149 -0
- package/framework/mcps/playwright-mcp/configs/opencode.json +9 -0
- package/framework/mcps/playwright-mcp/install.md +136 -0
- package/framework/mcps/playwright-mcp/troubleshooting.md +154 -0
- package/framework/mcps/supabase-mcp/README.md +66 -0
- package/framework/mcps/supabase-mcp/capabilities.md +127 -0
- package/framework/mcps/supabase-mcp/configs/opencode.json +9 -0
- package/framework/mcps/supabase-mcp/install.md +85 -0
- package/framework/mcps/supabase-mcp/troubleshooting.md +113 -0
- package/framework/memory/README.md +17 -0
- package/framework/memory/codebase-insights.md +6 -0
- package/framework/memory/user-preferences.md +5 -0
- package/framework/modes/README.md +52 -0
- package/framework/modes/audit.md +88 -0
- package/framework/plugins/README.md +65 -0
- package/framework/plugins/opencode-goal-plugin/README.md +45 -0
- package/framework/plugins/opencode-goal-plugin/capabilities.md +127 -0
- package/framework/plugins/opencode-goal-plugin/install.md +71 -0
- package/framework/plugins/opencode-goal-plugin/troubleshooting.md +112 -0
- package/framework/plugins/ponytail/README.md +44 -0
- package/framework/plugins/ponytail/capabilities.md +112 -0
- package/framework/plugins/ponytail/install.md +77 -0
- package/framework/plugins/ponytail/troubleshooting.md +116 -0
- package/framework/references/standards/api.md +44 -0
- package/framework/references/standards/architecture.md +43 -0
- package/framework/references/standards/database.md +43 -0
- package/framework/references/standards/debugging.md +44 -0
- package/framework/references/standards/documentation.md +43 -0
- package/framework/references/standards/logging.md +43 -0
- package/framework/references/standards/naming.md +43 -0
- package/framework/references/standards/observability.md +43 -0
- package/framework/references/standards/performance.md +43 -0
- package/framework/references/standards/pull-requests.md +43 -0
- package/framework/references/standards/security.md +43 -0
- package/framework/references/standards/testing.md +43 -0
- package/framework/references/templates/adr.md +28 -0
- package/framework/references/templates/api-spec.md +56 -0
- package/framework/references/templates/design-document.md +39 -0
- package/framework/references/templates/incident-report.md +38 -0
- package/framework/references/templates/postmortem.md +41 -0
- package/framework/references/templates/pull-request.md +34 -0
- package/framework/references/templates/runbook.md +48 -0
- package/framework/references/templates/task.md +27 -0
- package/framework/skills/README.md +68 -0
- package/framework/skills/agent-browser/SKILL.md +51 -0
- package/framework/skills/backend-best-practices/SKILL.md +136 -0
- package/framework/skills/backend-best-practices/examples.md +31 -0
- package/framework/skills/backend-best-practices/references/api-design.md +79 -0
- package/framework/skills/backend-best-practices/references/architecture-review.md +77 -0
- package/framework/skills/backend-best-practices/references/database-design.md +78 -0
- package/framework/skills/backend-best-practices/references/debugging.md +76 -0
- package/framework/skills/backend-best-practices/references/observability.md +78 -0
- package/framework/skills/backend-best-practices/references/performance.md +78 -0
- package/framework/skills/backend-best-practices/references/refactoring.md +77 -0
- package/framework/skills/backend-best-practices/references/security.md +80 -0
- package/framework/skills/backend-best-practices/references/testing.md +77 -0
- package/framework/skills/backend-engineer/SKILL.md +76 -0
- package/framework/skills/backend-engineer/examples.md +31 -0
- package/framework/skills/brainstorming/SKILL.md +159 -0
- package/framework/skills/brainstorming/examples.md +49 -0
- package/framework/skills/brainstorming/scripts/frame-template.html +213 -0
- package/framework/skills/brainstorming/scripts/helper.js +167 -0
- package/framework/skills/brainstorming/scripts/server.cjs +723 -0
- package/framework/skills/brainstorming/scripts/start-server.sh +209 -0
- package/framework/skills/brainstorming/scripts/stop-server.sh +120 -0
- package/framework/skills/brainstorming/visual-companion.md +291 -0
- package/framework/skills/brand-guidelines/LICENSE.txt +202 -0
- package/framework/skills/brand-guidelines/SKILL.md +73 -0
- package/framework/skills/code-review/SKILL.md +72 -0
- package/framework/skills/code-review/examples.md +31 -0
- package/framework/skills/design/SKILL.md +399 -0
- package/framework/skills/design/examples.md +34 -0
- package/framework/skills/diagram-design/SKILL.md +485 -0
- package/framework/skills/diagram-design/assets/example-architecture-dark.html +180 -0
- package/framework/skills/diagram-design/assets/example-architecture-full.html +192 -0
- package/framework/skills/diagram-design/assets/example-architecture.html +181 -0
- package/framework/skills/diagram-design/assets/example-bar-dark.html +127 -0
- package/framework/skills/diagram-design/assets/example-bar-full.html +103 -0
- package/framework/skills/diagram-design/assets/example-bar.html +127 -0
- package/framework/skills/diagram-design/assets/example-data-flow-dark.html +143 -0
- package/framework/skills/diagram-design/assets/example-data-flow-full.html +185 -0
- package/framework/skills/diagram-design/assets/example-data-flow.html +143 -0
- package/framework/skills/diagram-design/assets/example-datalake-dark.html +241 -0
- package/framework/skills/diagram-design/assets/example-datalake-full.html +246 -0
- package/framework/skills/diagram-design/assets/example-datalake.html +267 -0
- package/framework/skills/diagram-design/assets/example-dp-integration-dark.html +78 -0
- package/framework/skills/diagram-design/assets/example-dp-integration-full.html +88 -0
- package/framework/skills/diagram-design/assets/example-dp-integration.html +78 -0
- package/framework/skills/diagram-design/assets/example-dp-security-matrix-dark.html +31 -0
- package/framework/skills/diagram-design/assets/example-dp-security-matrix-full.html +32 -0
- package/framework/skills/diagram-design/assets/example-dp-security-matrix.html +88 -0
- package/framework/skills/diagram-design/assets/example-er-dark.html +200 -0
- package/framework/skills/diagram-design/assets/example-er-full.html +203 -0
- package/framework/skills/diagram-design/assets/example-er.html +200 -0
- package/framework/skills/diagram-design/assets/example-flowchart-dark.html +154 -0
- package/framework/skills/diagram-design/assets/example-flowchart-full.html +157 -0
- package/framework/skills/diagram-design/assets/example-flowchart.html +154 -0
- package/framework/skills/diagram-design/assets/example-gantt-dark.html +135 -0
- package/framework/skills/diagram-design/assets/example-gantt-full.html +125 -0
- package/framework/skills/diagram-design/assets/example-gantt.html +135 -0
- package/framework/skills/diagram-design/assets/example-high-level-dark.html +249 -0
- package/framework/skills/diagram-design/assets/example-high-level-full.html +245 -0
- package/framework/skills/diagram-design/assets/example-high-level-vertical-dark.html +272 -0
- package/framework/skills/diagram-design/assets/example-high-level-vertical-full.html +250 -0
- package/framework/skills/diagram-design/assets/example-high-level-vertical.html +323 -0
- package/framework/skills/diagram-design/assets/example-high-level.html +299 -0
- package/framework/skills/diagram-design/assets/example-it-state-dark.html +90 -0
- package/framework/skills/diagram-design/assets/example-it-state-full.html +69 -0
- package/framework/skills/diagram-design/assets/example-it-state.html +128 -0
- package/framework/skills/diagram-design/assets/example-layers-dark.html +121 -0
- package/framework/skills/diagram-design/assets/example-layers-full.html +124 -0
- package/framework/skills/diagram-design/assets/example-layers.html +121 -0
- package/framework/skills/diagram-design/assets/example-line-dark.html +109 -0
- package/framework/skills/diagram-design/assets/example-line-full.html +103 -0
- package/framework/skills/diagram-design/assets/example-line.html +109 -0
- package/framework/skills/diagram-design/assets/example-loop-dark.html +100 -0
- package/framework/skills/diagram-design/assets/example-loop-full.html +137 -0
- package/framework/skills/diagram-design/assets/example-loop-terminal.html +347 -0
- package/framework/skills/diagram-design/assets/example-loop.html +100 -0
- package/framework/skills/diagram-design/assets/example-medallion-dark.html +159 -0
- package/framework/skills/diagram-design/assets/example-medallion-full.html +201 -0
- package/framework/skills/diagram-design/assets/example-medallion.html +159 -0
- package/framework/skills/diagram-design/assets/example-nested-dark.html +130 -0
- package/framework/skills/diagram-design/assets/example-nested-full.html +133 -0
- package/framework/skills/diagram-design/assets/example-nested.html +134 -0
- package/framework/skills/diagram-design/assets/example-org-chart-dark.html +45 -0
- package/framework/skills/diagram-design/assets/example-org-chart-full.html +45 -0
- package/framework/skills/diagram-design/assets/example-org-chart.html +45 -0
- package/framework/skills/diagram-design/assets/example-process-dark.html +62 -0
- package/framework/skills/diagram-design/assets/example-process-full.html +72 -0
- package/framework/skills/diagram-design/assets/example-process.html +62 -0
- package/framework/skills/diagram-design/assets/example-pyramid-dark.html +117 -0
- package/framework/skills/diagram-design/assets/example-pyramid-full.html +120 -0
- package/framework/skills/diagram-design/assets/example-pyramid.html +117 -0
- package/framework/skills/diagram-design/assets/example-quadrant-consultant.html +164 -0
- package/framework/skills/diagram-design/assets/example-quadrant-dark.html +133 -0
- package/framework/skills/diagram-design/assets/example-quadrant-full.html +136 -0
- package/framework/skills/diagram-design/assets/example-quadrant.html +133 -0
- package/framework/skills/diagram-design/assets/example-radar-dark.html +137 -0
- package/framework/skills/diagram-design/assets/example-radar-full.html +133 -0
- package/framework/skills/diagram-design/assets/example-radar.html +137 -0
- package/framework/skills/diagram-design/assets/example-scatter-dark.html +139 -0
- package/framework/skills/diagram-design/assets/example-scatter-full.html +114 -0
- package/framework/skills/diagram-design/assets/example-scatter.html +139 -0
- package/framework/skills/diagram-design/assets/example-sequence-dark.html +220 -0
- package/framework/skills/diagram-design/assets/example-sequence-full.html +386 -0
- package/framework/skills/diagram-design/assets/example-sequence.html +220 -0
- package/framework/skills/diagram-design/assets/example-state-dark.html +145 -0
- package/framework/skills/diagram-design/assets/example-state-full.html +148 -0
- package/framework/skills/diagram-design/assets/example-state.html +145 -0
- package/framework/skills/diagram-design/assets/example-swimlane-dark.html +170 -0
- package/framework/skills/diagram-design/assets/example-swimlane-full.html +173 -0
- package/framework/skills/diagram-design/assets/example-swimlane.html +170 -0
- package/framework/skills/diagram-design/assets/example-timeline-dark.html +133 -0
- package/framework/skills/diagram-design/assets/example-timeline-full.html +136 -0
- package/framework/skills/diagram-design/assets/example-timeline.html +133 -0
- package/framework/skills/diagram-design/assets/example-tree-dark.html +171 -0
- package/framework/skills/diagram-design/assets/example-tree-full.html +174 -0
- package/framework/skills/diagram-design/assets/example-tree.html +171 -0
- package/framework/skills/diagram-design/assets/example-venn-dark.html +130 -0
- package/framework/skills/diagram-design/assets/example-venn-full.html +133 -0
- package/framework/skills/diagram-design/assets/example-venn.html +108 -0
- package/framework/skills/diagram-design/assets/icons.html +230 -0
- package/framework/skills/diagram-design/assets/index.html +333 -0
- package/framework/skills/diagram-design/assets/template-dark.html +82 -0
- package/framework/skills/diagram-design/assets/template-full.html +410 -0
- package/framework/skills/diagram-design/assets/template-terminal.html +170 -0
- package/framework/skills/diagram-design/assets/template.html +83 -0
- package/framework/skills/diagram-design/references/export.md +107 -0
- package/framework/skills/diagram-design/references/onboarding.md +268 -0
- package/framework/skills/diagram-design/references/primitive-annotation.md +36 -0
- package/framework/skills/diagram-design/references/primitive-icons.md +821 -0
- package/framework/skills/diagram-design/references/primitive-sketchy.md +43 -0
- package/framework/skills/diagram-design/references/primitive-terminal.md +76 -0
- package/framework/skills/diagram-design/references/style-guide.md +139 -0
- package/framework/skills/diagram-design/references/type-architecture.md +78 -0
- package/framework/skills/diagram-design/references/type-bar.md +48 -0
- package/framework/skills/diagram-design/references/type-data-flow.md +374 -0
- package/framework/skills/diagram-design/references/type-dp-integration.md +410 -0
- package/framework/skills/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/framework/skills/diagram-design/references/type-er.md +23 -0
- package/framework/skills/diagram-design/references/type-flowchart.md +23 -0
- package/framework/skills/diagram-design/references/type-gantt.md +45 -0
- package/framework/skills/diagram-design/references/type-high-level.md +458 -0
- package/framework/skills/diagram-design/references/type-it-state.md +470 -0
- package/framework/skills/diagram-design/references/type-layers.md +26 -0
- package/framework/skills/diagram-design/references/type-line.md +44 -0
- package/framework/skills/diagram-design/references/type-loop.md +223 -0
- package/framework/skills/diagram-design/references/type-medallion.md +356 -0
- package/framework/skills/diagram-design/references/type-nested.md +22 -0
- package/framework/skills/diagram-design/references/type-org-chart.md +44 -0
- package/framework/skills/diagram-design/references/type-process.md +495 -0
- package/framework/skills/diagram-design/references/type-pyramid.md +33 -0
- package/framework/skills/diagram-design/references/type-quadrant.md +81 -0
- package/framework/skills/diagram-design/references/type-radar.md +80 -0
- package/framework/skills/diagram-design/references/type-scatter.md +39 -0
- package/framework/skills/diagram-design/references/type-sequence.md +35 -0
- package/framework/skills/diagram-design/references/type-state.md +21 -0
- package/framework/skills/diagram-design/references/type-swimlane.md +20 -0
- package/framework/skills/diagram-design/references/type-timeline.md +20 -0
- package/framework/skills/diagram-design/references/type-tree.md +24 -0
- package/framework/skills/diagram-design/references/type-venn.md +26 -0
- package/framework/skills/documentation/SKILL.md +74 -0
- package/framework/skills/documentation/examples.md +31 -0
- package/framework/skills/find-skills/SKILL.md +141 -0
- package/framework/skills/find-skills/examples.md +35 -0
- package/framework/skills/gitlab-mcp/SKILL.md +83 -0
- package/framework/skills/gitlab-mcp/examples.md +31 -0
- package/framework/skills/gitlab-mcp/references/code-review.md +110 -0
- package/framework/skills/gitlab-mcp/references/issues.md +141 -0
- package/framework/skills/gitlab-mcp/references/merge-requests.md +120 -0
- package/framework/skills/gitlab-mcp/references/pipelines.md +67 -0
- package/framework/skills/gitlab-mcp/references/search.md +17 -0
- package/framework/skills/gitlab-mcp/references/webhooks.md +32 -0
- package/framework/skills/gitlab-mcp/references/work-items.md +50 -0
- package/framework/skills/jira-mcp/SKILL.md +57 -0
- package/framework/skills/jira-mcp/examples.md +31 -0
- package/framework/skills/jira-mcp/references/comments.md +27 -0
- package/framework/skills/jira-mcp/references/issues.md +97 -0
- package/framework/skills/jira-mcp/references/projects.md +39 -0
- package/framework/skills/laravel-best-practices/SKILL.md +229 -0
- package/framework/skills/laravel-best-practices/examples.md +31 -0
- package/framework/skills/laravel-best-practices/references/advanced-queries.md +106 -0
- package/framework/skills/laravel-best-practices/references/architecture.md +202 -0
- package/framework/skills/laravel-best-practices/references/blade-views.md +36 -0
- package/framework/skills/laravel-best-practices/references/caching.md +70 -0
- package/framework/skills/laravel-best-practices/references/collections.md +44 -0
- package/framework/skills/laravel-best-practices/references/config.md +73 -0
- package/framework/skills/laravel-best-practices/references/db-performance.md +192 -0
- package/framework/skills/laravel-best-practices/references/eloquent.md +148 -0
- package/framework/skills/laravel-best-practices/references/error-handling.md +72 -0
- package/framework/skills/laravel-best-practices/references/events-notifications.md +52 -0
- package/framework/skills/laravel-best-practices/references/http-client.md +160 -0
- package/framework/skills/laravel-best-practices/references/mail.md +27 -0
- package/framework/skills/laravel-best-practices/references/migrations.md +121 -0
- package/framework/skills/laravel-best-practices/references/passport.md +197 -0
- package/framework/skills/laravel-best-practices/references/pennant.md +61 -0
- package/framework/skills/laravel-best-practices/references/pest-testing.md +166 -0
- package/framework/skills/laravel-best-practices/references/pulse.md +196 -0
- package/framework/skills/laravel-best-practices/references/queue-jobs.md +144 -0
- package/framework/skills/laravel-best-practices/references/routing.md +99 -0
- package/framework/skills/laravel-best-practices/references/scheduling.md +39 -0
- package/framework/skills/laravel-best-practices/references/scout.md +176 -0
- package/framework/skills/laravel-best-practices/references/security.md +198 -0
- package/framework/skills/laravel-best-practices/references/spatie-laravel-backup.md +222 -0
- package/framework/skills/laravel-best-practices/references/spatie-laravel-permission.md +272 -0
- package/framework/skills/laravel-best-practices/references/spatie-medialibrary.md +672 -0
- package/framework/skills/laravel-best-practices/references/style.md +125 -0
- package/framework/skills/laravel-best-practices/references/tailwindcss.md +112 -0
- package/framework/skills/laravel-best-practices/references/testing.md +43 -0
- package/framework/skills/laravel-best-practices/references/validation.md +75 -0
- package/framework/skills/lavish/SKILL.md +67 -0
- package/framework/skills/lavish/examples.md +31 -0
- package/framework/skills/notion-mcp/SKILL.md +57 -0
- package/framework/skills/notion-mcp/examples.md +31 -0
- package/framework/skills/notion-mcp/references/comments.md +112 -0
- package/framework/skills/notion-mcp/references/databases.md +193 -0
- package/framework/skills/notion-mcp/references/pages.md +235 -0
- package/framework/skills/skill-creator/LICENSE.txt +202 -0
- package/framework/skills/skill-creator/SKILL.md +485 -0
- package/framework/skills/skill-creator/agents/analyzer.md +274 -0
- package/framework/skills/skill-creator/agents/comparator.md +202 -0
- package/framework/skills/skill-creator/agents/grader.md +223 -0
- package/framework/skills/skill-creator/assets/eval_review.html +146 -0
- package/framework/skills/skill-creator/eval-viewer/generate_review.py +471 -0
- package/framework/skills/skill-creator/eval-viewer/viewer.html +1325 -0
- package/framework/skills/skill-creator/examples.md +31 -0
- package/framework/skills/skill-creator/references/schemas.md +430 -0
- package/framework/skills/skill-creator/scripts/__init__.py +0 -0
- package/framework/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
- package/framework/skills/skill-creator/scripts/generate_report.py +326 -0
- package/framework/skills/skill-creator/scripts/improve_description.py +247 -0
- package/framework/skills/skill-creator/scripts/package_skill.py +136 -0
- package/framework/skills/skill-creator/scripts/quick_validate.py +103 -0
- package/framework/skills/skill-creator/scripts/run_eval.py +310 -0
- package/framework/skills/skill-creator/scripts/run_loop.py +328 -0
- package/framework/skills/skill-creator/scripts/utils.py +47 -0
- package/framework/styles/README.md +35 -0
- package/framework/styles/linear/DESIGN.md +478 -0
- package/framework/styles/linear/README.md +36 -0
- package/framework/styles/linear/assets/preview.jpg +0 -0
- package/framework/styles/raycast/DESIGN.md +495 -0
- package/framework/styles/raycast/README.md +35 -0
- package/framework/styles/raycast/assets/preview.jpg +0 -0
- package/package.json +33 -0
- package/src/agent-configs.js +96 -0
- package/src/catalog.js +145 -0
- package/src/cli.js +254 -0
- package/src/installer.js +303 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Issue Management
|
|
2
|
+
|
|
3
|
+
## Create
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
create_issue
|
|
7
|
+
projectKey: "PROJ"
|
|
8
|
+
summary: "Login page returns 500"
|
|
9
|
+
issueType: "Bug"
|
|
10
|
+
description: "Steps to reproduce..."
|
|
11
|
+
priority: "High"
|
|
12
|
+
labels: ["bug", "critical"]
|
|
13
|
+
assignee: "john.doe"
|
|
14
|
+
components: ["frontend"]
|
|
15
|
+
customfield_10211: "Sprint 1" # optional custom fields
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Always verify project and issue types first:
|
|
19
|
+
|
|
20
|
+
1. `get_projects` → find project key
|
|
21
|
+
2. `get_issue_types` with `projectKey: "PROJ"` → find valid types
|
|
22
|
+
3. `create_issue` with valid `projectKey` and `issueType`
|
|
23
|
+
|
|
24
|
+
## Read
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
get_issue
|
|
28
|
+
issueKey: "PROJ-123"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Returns full issue details: summary, description, status, priority, assignee, reporter, labels, components, custom fields, timestamps.
|
|
32
|
+
|
|
33
|
+
## Search (JQL)
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
search_issues
|
|
37
|
+
jql: "project = PROJ AND status = Open"
|
|
38
|
+
maxResults: 50
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Common JQL Patterns
|
|
42
|
+
|
|
43
|
+
| Purpose | JQL |
|
|
44
|
+
| ------- | --- |
|
|
45
|
+
| My open issues | `assignee = currentUser() AND status != Done` |
|
|
46
|
+
| High priority recent | `priority = High AND created >= -7d` |
|
|
47
|
+
| By status | `status IN (Open, "In Progress", "Reopened")` |
|
|
48
|
+
| By label | `labels = "bug" OR labels = "critical"` |
|
|
49
|
+
| By reporter | `reporter = john.doe AND status NOT IN (Closed, Done)` |
|
|
50
|
+
| Unassigned | `assignee IS NULL AND status NOT IN (Closed, Done, Resolved)` |
|
|
51
|
+
| Sprints (custom field) | `cf[10211] = "Sprint 1"` |
|
|
52
|
+
| Date range | `created >= "2025-01-01" AND created <= "2025-06-01"` |
|
|
53
|
+
| Order by | `project = PROJ ORDER BY priority DESC, created ASC` |
|
|
54
|
+
| Text search | `text ~ "error message"` |
|
|
55
|
+
| Across all projects | `status = Open AND assignee = currentUser()` |
|
|
56
|
+
|
|
57
|
+
`search_issues` defaults to showing issues across **all projects** the user has access to. Scope to a specific project with `project = KEY`.
|
|
58
|
+
|
|
59
|
+
## Update
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
update_issue
|
|
63
|
+
issueKey: "PROJ-123"
|
|
64
|
+
summary: "Updated title"
|
|
65
|
+
description: "New description"
|
|
66
|
+
priority: "Low"
|
|
67
|
+
assignee: "jane.doe"
|
|
68
|
+
labels: ["bug", "resolved"]
|
|
69
|
+
status: "In Progress" # transition to new status
|
|
70
|
+
customfield_10211: "Sprint 2"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Status Transitions
|
|
74
|
+
|
|
75
|
+
- Issue workflow statuses depend on the project's configuration
|
|
76
|
+
- Common transitions: `Open → "In Progress" → "In Review" → "Done" | "Closed"`
|
|
77
|
+
- Use `get_issue` to check current status and `update_issue` with `status` to transition
|
|
78
|
+
- Invalid transitions return an error — check the project's available workflow transitions in Jira
|
|
79
|
+
|
|
80
|
+
## Assign
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
assign_issue
|
|
84
|
+
issueKey: "PROJ-123"
|
|
85
|
+
assignee: "john.doe"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`assign_issue` is a dedicated tool. You can also assign via `update_issue` with `assignee`.
|
|
89
|
+
|
|
90
|
+
## Delete
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
delete_issue
|
|
94
|
+
issueKey: "PROJ-123"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Warning**: `delete_issue` is destructive — permanently deletes the issue. Cannot be undone.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Project Management
|
|
2
|
+
|
|
3
|
+
## List Projects
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
get_projects
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Returns all Jira projects the authenticated user can access. Each entry includes `key`, `name`, `projectTypeKey`, `lead`, and `avatarUrls`.
|
|
10
|
+
|
|
11
|
+
Use this to discover available `projectKey` values for issue operations.
|
|
12
|
+
|
|
13
|
+
## Project Details
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
get_project
|
|
17
|
+
projectKey: "PROJ"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Returns detailed information: name, key, description, lead, components, versions (releases), project type, and category.
|
|
21
|
+
|
|
22
|
+
Verify a project exists and inspect its components/versions before creating issues:
|
|
23
|
+
|
|
24
|
+
1. `get_project` → check components, versions
|
|
25
|
+
2. `get_issue_types` → check valid issue types
|
|
26
|
+
3. `create_issue` with verified data
|
|
27
|
+
|
|
28
|
+
## Issue Types
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
get_issue_types
|
|
32
|
+
projectKey: "PROJ"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Returns available issue types for a project. Each type includes `name`, `id`, `description`, `iconUrl`, and `subtask` flag.
|
|
36
|
+
|
|
37
|
+
Common types across most projects: `Bug`, `Task`, `Story`, `Epic`, `Sub-task`, `Improvement`, `New Feature`.
|
|
38
|
+
|
|
39
|
+
Always call this **before** creating an issue to ensure the `issueType` value is valid for the target project.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: laravel-best-practices
|
|
3
|
+
description: "Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code."
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Laravel Best Practices
|
|
8
|
+
|
|
9
|
+
Best practices for Laravel, prioritized by impact. Each rule teaches what to do and why. For exact API syntax, verify with `search-docs`.
|
|
10
|
+
|
|
11
|
+
## Consistency First
|
|
12
|
+
|
|
13
|
+
Before applying any rule, check what the application already does. Laravel offers multiple valid approaches — the best choice is the one the codebase already uses, even if another pattern would be theoretically better. Inconsistency is worse than a suboptimal pattern.
|
|
14
|
+
|
|
15
|
+
Check sibling files, related controllers, models, or tests for established patterns. If one exists, follow it — don't introduce a second way. These rules are defaults for when no pattern exists yet, not overrides.
|
|
16
|
+
|
|
17
|
+
## Quick Reference
|
|
18
|
+
|
|
19
|
+
### 1. Database Performance → `references/db-performance.md`
|
|
20
|
+
|
|
21
|
+
- Eager load with `with()` to prevent N+1 queries
|
|
22
|
+
- Enable `Model::preventLazyLoading()` in development
|
|
23
|
+
- Select only needed columns, avoid `SELECT *`
|
|
24
|
+
- `chunk()` / `chunkById()` for large datasets
|
|
25
|
+
- Index columns used in `WHERE`, `ORDER BY`, `JOIN`
|
|
26
|
+
- `withCount()` instead of loading relations to count
|
|
27
|
+
- `cursor()` for memory-efficient read-only iteration
|
|
28
|
+
- Never query in Blade templates
|
|
29
|
+
|
|
30
|
+
### 2. Advanced Query Patterns → `references/advanced-queries.md`
|
|
31
|
+
|
|
32
|
+
- `addSelect()` subqueries over eager-loading entire has-many for a single value
|
|
33
|
+
- Dynamic relationships via subquery FK + `belongsTo`
|
|
34
|
+
- Conditional aggregates (`CASE WHEN` in `selectRaw`) over multiple count queries
|
|
35
|
+
- `setRelation()` to prevent circular N+1 queries
|
|
36
|
+
- `whereIn` + `pluck()` over `whereHas` for better index usage
|
|
37
|
+
- Two simple queries can beat one complex query
|
|
38
|
+
- Compound indexes matching `orderBy` column order
|
|
39
|
+
- Correlated subqueries in `orderBy` for has-many sorting (avoid joins)
|
|
40
|
+
|
|
41
|
+
### 3. Security → `references/security.md`, `references/passport.md`, `references/spatie-laravel-permission.md`
|
|
42
|
+
|
|
43
|
+
- Define `$fillable` or `$guarded` on every model, authorize every action via policies or gates
|
|
44
|
+
- No raw SQL with user input — use Eloquent or query builder
|
|
45
|
+
- `{{ }}` for output escaping, `@csrf` on all POST/PUT/DELETE forms, `throttle` on auth and API routes
|
|
46
|
+
- Validate MIME type, extension, and size for file uploads
|
|
47
|
+
- Never commit `.env`, use `config()` for secrets, `encrypted` cast for sensitive DB fields
|
|
48
|
+
|
|
49
|
+
### 4. Caching → `references/caching.md`
|
|
50
|
+
|
|
51
|
+
- `Cache::remember()` over manual get/put
|
|
52
|
+
- `Cache::flexible()` for stale-while-revalidate on high-traffic data
|
|
53
|
+
- `Cache::memo()` to avoid redundant cache hits within a request
|
|
54
|
+
- Cache tags to invalidate related groups
|
|
55
|
+
- `Cache::add()` for atomic conditional writes
|
|
56
|
+
- `once()` to memoize per-request or per-object lifetime
|
|
57
|
+
- `Cache::lock()` / `lockForUpdate()` for race conditions
|
|
58
|
+
- Failover cache stores in production
|
|
59
|
+
|
|
60
|
+
### 5. Eloquent Patterns → `references/eloquent.md`
|
|
61
|
+
|
|
62
|
+
- Correct relationship types with return type hints
|
|
63
|
+
- Local scopes for reusable query constraints
|
|
64
|
+
- Global scopes sparingly — document their existence
|
|
65
|
+
- Attribute casts in the `casts()` method
|
|
66
|
+
- Cast date columns, use Carbon instances in templates
|
|
67
|
+
- `whereBelongsTo($model)` for cleaner queries
|
|
68
|
+
- Never hardcode table names — use `(new Model)->getTable()` or Eloquent queries
|
|
69
|
+
|
|
70
|
+
### 6. Validation & Forms → `references/validation.md`
|
|
71
|
+
|
|
72
|
+
- Form Request classes, not inline validation
|
|
73
|
+
- Array notation `['required', 'email']` for new code; follow existing convention
|
|
74
|
+
- `$request->validated()` only — never `$request->all()`
|
|
75
|
+
- `Rule::when()` for conditional validation
|
|
76
|
+
- `after()` instead of `withValidator()`
|
|
77
|
+
|
|
78
|
+
### 7. Configuration → `references/config.md`
|
|
79
|
+
|
|
80
|
+
- `env()` only inside config files
|
|
81
|
+
- `App::environment()` or `app()->isProduction()`
|
|
82
|
+
- Config, lang files, and constants over hardcoded text
|
|
83
|
+
|
|
84
|
+
### 8. Testing Patterns → `references/testing.md`, `references/pest-testing.md`
|
|
85
|
+
|
|
86
|
+
- `LazilyRefreshDatabase` over `RefreshDatabase` for speed
|
|
87
|
+
- `assertModelExists()` over raw `assertDatabaseHas()`
|
|
88
|
+
- Factory states and sequences over manual overrides
|
|
89
|
+
- Use fakes (`Event::fake()`, `Exceptions::fake()`, etc.) — but always after factory setup, not before
|
|
90
|
+
- `recycle()` to share relationship instances across factories
|
|
91
|
+
|
|
92
|
+
### 9. Queue & Job Patterns → `references/queue-jobs.md`
|
|
93
|
+
|
|
94
|
+
- `retry_after` must exceed job `timeout`; use exponential backoff `[1, 5, 10]`
|
|
95
|
+
- `ShouldBeUnique` to prevent duplicates; `ShouldBeUniqueUntilProcessing` for early lock release
|
|
96
|
+
- Always implement `failed()`; with `retryUntil()`, set `$tries = 0`
|
|
97
|
+
- `RateLimited` middleware for external API calls; `Bus::batch()` for related jobs
|
|
98
|
+
- Horizon for complex multi-queue scenarios
|
|
99
|
+
|
|
100
|
+
### 10. Routing & Controllers → `references/routing.md`
|
|
101
|
+
|
|
102
|
+
- Implicit route model binding
|
|
103
|
+
- Scoped bindings for nested resources
|
|
104
|
+
- `Route::resource()` or `apiResource()`
|
|
105
|
+
- Methods under 10 lines — extract to actions/services
|
|
106
|
+
- Type-hint Form Requests for auto-validation
|
|
107
|
+
|
|
108
|
+
### 11. HTTP Client → `references/http-client.md`
|
|
109
|
+
|
|
110
|
+
- Explicit `timeout` and `connectTimeout` on every request
|
|
111
|
+
- `retry()` with exponential backoff for external APIs
|
|
112
|
+
- Check response status or use `throw()`
|
|
113
|
+
- `Http::pool()` for concurrent independent requests
|
|
114
|
+
- `Http::fake()` and `preventStrayRequests()` in tests
|
|
115
|
+
|
|
116
|
+
### 12. Events, Notifications & Mail → `references/events-notifications.md`, `references/mail.md`
|
|
117
|
+
|
|
118
|
+
- Event discovery over manual registration; `event:cache` in production
|
|
119
|
+
- `ShouldDispatchAfterCommit` / `afterCommit()` inside transactions
|
|
120
|
+
- Queue notifications and mailables with `ShouldQueue`
|
|
121
|
+
- On-demand notifications for non-user recipients
|
|
122
|
+
- `HasLocalePreference` on notifiable models
|
|
123
|
+
- `assertQueued()` not `assertSent()` for queued mailables
|
|
124
|
+
- Markdown mailables for transactional emails
|
|
125
|
+
|
|
126
|
+
### 13. Error Handling → `references/error-handling.md`
|
|
127
|
+
|
|
128
|
+
- `report()`/`render()` on exception classes or in `bootstrap/app.php` — follow existing pattern
|
|
129
|
+
- `ShouldntReport` for exceptions that should never log
|
|
130
|
+
- Throttle high-volume exceptions to protect log sinks
|
|
131
|
+
- `dontReportDuplicates()` for multi-catch scenarios
|
|
132
|
+
- Force JSON rendering for API routes
|
|
133
|
+
- Structured context via `context()` on exception classes
|
|
134
|
+
|
|
135
|
+
### 14. Task Scheduling → `references/scheduling.md`
|
|
136
|
+
|
|
137
|
+
- `withoutOverlapping()` on variable-duration tasks
|
|
138
|
+
- `onOneServer()` on multi-server deployments
|
|
139
|
+
- `runInBackground()` for concurrent long tasks
|
|
140
|
+
- `environments()` to restrict to appropriate environments
|
|
141
|
+
- `takeUntilTimeout()` for time-bounded processing
|
|
142
|
+
- Schedule groups for shared configuration
|
|
143
|
+
|
|
144
|
+
### 15. Architecture → `references/architecture.md`
|
|
145
|
+
|
|
146
|
+
- Single-purpose Action classes; dependency injection over `app()` helper
|
|
147
|
+
- Prefer official Laravel packages and follow conventions, don't override defaults
|
|
148
|
+
- Default to `ORDER BY id DESC` or `created_at DESC`; `mb_*` for UTF-8 safety
|
|
149
|
+
- `defer()` for post-response work; `Context` for request-scoped data; `Concurrency::run()` for parallel execution
|
|
150
|
+
|
|
151
|
+
### 16. Migrations → `references/migrations.md`
|
|
152
|
+
|
|
153
|
+
- Generate migrations with `php artisan make:migration`
|
|
154
|
+
- `constrained()` for foreign keys
|
|
155
|
+
- Never modify migrations that have run in production
|
|
156
|
+
- Add indexes in the migration, not as an afterthought
|
|
157
|
+
- Mirror column defaults in model `$attributes`
|
|
158
|
+
- Reversible `down()` by default; forward-fix migrations for intentionally irreversible changes
|
|
159
|
+
- One concern per migration — never mix DDL and DML
|
|
160
|
+
|
|
161
|
+
### 17. Collections → `references/collections.md`
|
|
162
|
+
|
|
163
|
+
- Higher-order messages for simple collection operations
|
|
164
|
+
- `cursor()` vs. `lazy()` — choose based on relationship needs
|
|
165
|
+
- `lazyById()` when updating records while iterating
|
|
166
|
+
- `toQuery()` for bulk operations on collections
|
|
167
|
+
|
|
168
|
+
### 18. Blade & Views → `references/blade-views.md`, `references/tailwindcss.md`
|
|
169
|
+
|
|
170
|
+
- `$attributes->merge()` in component templates
|
|
171
|
+
- Blade components over `@include`; `@pushOnce` for per-component scripts
|
|
172
|
+
- View Composers for shared view data
|
|
173
|
+
- `@aware` for deeply nested component props
|
|
174
|
+
|
|
175
|
+
### 19. Conventions & Style → `references/style.md`
|
|
176
|
+
|
|
177
|
+
- Follow Laravel naming conventions for all entities
|
|
178
|
+
- Prefer Laravel helpers (`Str`, `Arr`, `Number`, `Uri`, `Str::of()`, `$request->string()`) over raw PHP functions
|
|
179
|
+
- No JS/CSS in Blade, no HTML in PHP classes
|
|
180
|
+
- Code should be readable; comments only for config files
|
|
181
|
+
|
|
182
|
+
### 20. Feature Flags → `references/pennant.md`
|
|
183
|
+
|
|
184
|
+
- `Feature::define()` to define features with resolver callbacks
|
|
185
|
+
- `Feature::active()` / `@feature` Blade directive to check features
|
|
186
|
+
- Scope features to specific users/entities with `Feature::for()`
|
|
187
|
+
- `Feature::activate()` / `deactivate()` for runtime control
|
|
188
|
+
|
|
189
|
+
### 21. Monitoring → `references/pulse.md`
|
|
190
|
+
|
|
191
|
+
- Gate-protect the dashboard with `viewPulse` gate
|
|
192
|
+
- Configure built-in recorders in `config/pulse.php` (SlowQueries, SlowRequests, Exceptions, Queues, etc.)
|
|
193
|
+
- Redis ingest for production performance; run `pulse:work` to drain the stream
|
|
194
|
+
- Custom cards via Livewire components extending `Pulse\Card`
|
|
195
|
+
- `Pulse::filter()` to exclude entries; `Pulse::resolveAuthenticatedUserId()` for multi-model apps
|
|
196
|
+
- `pulse:check` daemon required for Servers card
|
|
197
|
+
|
|
198
|
+
### 22. Full-Text Search → `references/scout.md`
|
|
199
|
+
|
|
200
|
+
- Add `Searchable` trait to models for automatic index sync
|
|
201
|
+
- Choose engine: Database, Collection, Algolia, Meilisearch, Typesense
|
|
202
|
+
- `toSearchableArray()` to control indexed data; `searchableAs()` for custom index names
|
|
203
|
+
- `Model::search('query')->where(...)->paginate()` for search queries
|
|
204
|
+
- `scout:import` / `scout:flush` for index management; `scout:sync-index-settings` for engine config
|
|
205
|
+
- `Model::withoutSyncingToSearch()` / `SCOUT_DRIVER=null` for testing
|
|
206
|
+
|
|
207
|
+
### 23. Backup → `references/spatie-laravel-backup.md`
|
|
208
|
+
|
|
209
|
+
- Schedule `backup:run`, `backup:clean`, `backup:monitor` in console kernel
|
|
210
|
+
- Configure sources, destinations, notifications in `config/backup.php`
|
|
211
|
+
- Custom cleanup strategies extending `CleanupStrategy`
|
|
212
|
+
- Custom health checks extending `HealthCheck`
|
|
213
|
+
- Enable encryption and Gzip compression via config
|
|
214
|
+
|
|
215
|
+
### 24. Media Library → `references/spatie-medialibrary.md`
|
|
216
|
+
|
|
217
|
+
- Implement `HasMedia` interface + `InteractsWithMedia` trait on models
|
|
218
|
+
- `addMedia()` / `addMediaFromRequest()` for file uploads
|
|
219
|
+
- Media collections to organize related files per model
|
|
220
|
+
- Conversions for image processing (thumbnails, crops, etc.)
|
|
221
|
+
- Responsive images via conversion `withResponsiveImages()`
|
|
222
|
+
|
|
223
|
+
## How to Apply
|
|
224
|
+
|
|
225
|
+
Always use a sub-agent to read rule files and explore this skill's content.
|
|
226
|
+
|
|
227
|
+
1. Identify the file type and select relevant sections (e.g., migration → §16, controller → §1, §3, §5, §6, §10)
|
|
228
|
+
2. Check sibling files for existing patterns — follow those first per Consistency First
|
|
229
|
+
3. Verify API syntax with `search-docs` for the installed Laravel version
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Laravel Best Practices Examples
|
|
2
|
+
|
|
3
|
+
## Example 1: Refactor Controller Logic
|
|
4
|
+
|
|
5
|
+
A controller action contains five responsibilities: validation, authorization, querying, formatting, and logging. Good agent behavior:
|
|
6
|
+
|
|
7
|
+
- Extract validation into a Form Request class with `authorize()` and `rules()` methods.
|
|
8
|
+
- Move authorization checks into a Policy class with a named method matching the action.
|
|
9
|
+
- Extract query logic into a repository or service class with a single responsibility.
|
|
10
|
+
- Use API resources for response formatting instead of inline `toArray()` calls.
|
|
11
|
+
- Use Laravel's built-in logging channel with structured context instead of `Log::debug()` scattered through the controller.
|
|
12
|
+
|
|
13
|
+
## Example 2: Fix N+1 Query Performance
|
|
14
|
+
|
|
15
|
+
A page loads slowly because a loop calls a relationship query for every item. Good agent behavior:
|
|
16
|
+
|
|
17
|
+
- Identify the N+1 pattern: the loop accesses `$post->comments` inside a Blade `@foreach`.
|
|
18
|
+
- Use `$posts->load('comments')` for eager loading, or use `with('comments')` on the initial query.
|
|
19
|
+
- Check for deeper nested relationships that would cause additional N+1 patterns.
|
|
20
|
+
- Add `select` and `where` constraints on the eager-loaded relationship to avoid fetching unnecessary data.
|
|
21
|
+
- Verify the fix reduces query count from N+1 to 2 with `DB::enableQueryLog`.
|
|
22
|
+
|
|
23
|
+
## Example 3: Secure API Endpoint
|
|
24
|
+
|
|
25
|
+
An API endpoint allows any authenticated user to delete any order. Good agent behavior:
|
|
26
|
+
|
|
27
|
+
- Create a Policy with a `delete` method that verifies the order belongs to the user.
|
|
28
|
+
- Register the policy in `AuthServiceProvider`.
|
|
29
|
+
- Use `$this->authorize('delete', $order)` in the controller instead of inline `if` checks.
|
|
30
|
+
- Add a Form Request to validate the delete action input (order ID, reason).
|
|
31
|
+
- Write a unit test for the policy denying access to orders owned by other users.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Advanced Query Patterns
|
|
2
|
+
|
|
3
|
+
## Use `addSelect()` Subqueries for Single Values from Has-Many
|
|
4
|
+
|
|
5
|
+
Instead of eager-loading an entire has-many relationship for a single value (like the latest timestamp), use a correlated subquery via `addSelect()`. This pulls the value directly in the main SQL query — zero extra queries.
|
|
6
|
+
|
|
7
|
+
```php
|
|
8
|
+
public function scopeWithLastLoginAt($query): void
|
|
9
|
+
{
|
|
10
|
+
$query->addSelect([
|
|
11
|
+
'last_login_at' => Login::select('created_at')
|
|
12
|
+
->whereColumn('user_id', 'users.id')
|
|
13
|
+
->latest()
|
|
14
|
+
->take(1),
|
|
15
|
+
])->withCasts(['last_login_at' => 'datetime']);
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Create Dynamic Relationships via Subquery FK
|
|
20
|
+
|
|
21
|
+
Extend the `addSelect()` pattern to fetch a foreign key via subquery, then define a `belongsTo` relationship on that virtual attribute. This provides a fully-hydrated related model without loading the entire collection.
|
|
22
|
+
|
|
23
|
+
```php
|
|
24
|
+
public function lastLogin(): BelongsTo
|
|
25
|
+
{
|
|
26
|
+
return $this->belongsTo(Login::class);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public function scopeWithLastLogin($query): void
|
|
30
|
+
{
|
|
31
|
+
$query->addSelect([
|
|
32
|
+
'last_login_id' => Login::select('id')
|
|
33
|
+
->whereColumn('user_id', 'users.id')
|
|
34
|
+
->latest()
|
|
35
|
+
->take(1),
|
|
36
|
+
])->with('lastLogin');
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Use Conditional Aggregates Instead of Multiple Count Queries
|
|
41
|
+
|
|
42
|
+
Replace N separate `count()` queries with a single query using `CASE WHEN` inside `selectRaw()`. Use `toBase()` to skip model hydration when you only need scalar values.
|
|
43
|
+
|
|
44
|
+
```php
|
|
45
|
+
$statuses = Feature::toBase()
|
|
46
|
+
->selectRaw("count(case when status = 'Requested' then 1 end) as requested")
|
|
47
|
+
->selectRaw("count(case when status = 'Planned' then 1 end) as planned")
|
|
48
|
+
->selectRaw("count(case when status = 'Completed' then 1 end) as completed")
|
|
49
|
+
->first();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Use `setRelation()` to Prevent Circular N+1
|
|
53
|
+
|
|
54
|
+
When a parent model is eager-loaded with its children, and the view also needs `$child->parent`, use `setRelation()` to inject the already-loaded parent rather than letting Eloquent fire N additional queries.
|
|
55
|
+
|
|
56
|
+
```php
|
|
57
|
+
$feature->load('comments.user');
|
|
58
|
+
$feature->comments->each->setRelation('feature', $feature);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Prefer `whereIn` + Subquery Over `whereHas`
|
|
62
|
+
|
|
63
|
+
`whereHas()` emits a correlated `EXISTS` subquery that re-executes per row. Using `whereIn()` with a `select('id')` subquery lets the database use an index lookup instead, without loading data into PHP memory.
|
|
64
|
+
|
|
65
|
+
Incorrect (correlated EXISTS re-executes per row):
|
|
66
|
+
|
|
67
|
+
```php
|
|
68
|
+
$query->whereHas('company', fn ($q) => $q->where('name', 'like', $term));
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Correct (index-friendly subquery, no PHP memory overhead):
|
|
72
|
+
|
|
73
|
+
```php
|
|
74
|
+
$query->whereIn('company_id', Company::where('name', 'like', $term)->select('id'));
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Sometimes Two Simple Queries Beat One Complex Query
|
|
78
|
+
|
|
79
|
+
Running a small, targeted secondary query and passing its results via `whereIn` is often faster than a single complex correlated subquery or join. The additional round-trip is worthwhile when the secondary query is highly selective and uses its own index.
|
|
80
|
+
|
|
81
|
+
## Use Compound Indexes Matching `orderBy` Column Order
|
|
82
|
+
|
|
83
|
+
When ordering by multiple columns, create a single compound index in the same column order as the `ORDER BY` clause. Individual single-column indexes cannot combine for multi-column sorts — the database will filesort without a compound index.
|
|
84
|
+
|
|
85
|
+
```php
|
|
86
|
+
// Migration
|
|
87
|
+
$table->index(['last_name', 'first_name']);
|
|
88
|
+
|
|
89
|
+
// Query — column order must match the index
|
|
90
|
+
User::query()->orderBy('last_name')->orderBy('first_name')->paginate();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Use Correlated Subqueries for Has-Many Ordering
|
|
94
|
+
|
|
95
|
+
When sorting by a value from a has-many relationship, avoid joins (they duplicate rows). Use a correlated subquery inside `orderBy()` instead, paired with an `addSelect` scope for eager loading.
|
|
96
|
+
|
|
97
|
+
```php
|
|
98
|
+
public function scopeOrderByLastLogin($query): void
|
|
99
|
+
{
|
|
100
|
+
$query->orderByDesc(Login::select('created_at')
|
|
101
|
+
->whereColumn('user_id', 'users.id')
|
|
102
|
+
->latest()
|
|
103
|
+
->take(1)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|