@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,672 @@
|
|
|
1
|
+
# Media Library Development
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Use spatie/laravel-medialibrary to associate files with Eloquent models. Supports image/video conversions, responsive images, multiple collections, and various storage disks.
|
|
6
|
+
|
|
7
|
+
## When to Activate
|
|
8
|
+
|
|
9
|
+
- Activate when working with file uploads, media attachments, or image processing in Laravel.
|
|
10
|
+
- Activate when code references `HasMedia`, `InteractsWithMedia`, the `Media` model, or media collections/conversions.
|
|
11
|
+
- Activate when the user wants to add, retrieve, convert, or manage files attached to Eloquent models.
|
|
12
|
+
|
|
13
|
+
## Scope
|
|
14
|
+
|
|
15
|
+
- In scope: media uploads, collections, conversions, responsive images, custom properties, file retrieval, path/URL generation.
|
|
16
|
+
- Out of scope: general file storage without Eloquent association, non-Laravel frameworks.
|
|
17
|
+
|
|
18
|
+
## Workflow
|
|
19
|
+
|
|
20
|
+
1. Identify the task (model setup, adding media, defining conversions, retrieving files, etc.).
|
|
21
|
+
2. Read `Laravel Media Library Reference` and focus on the relevant section.
|
|
22
|
+
3. Apply the patterns from the reference, keeping code minimal and Laravel-native.
|
|
23
|
+
|
|
24
|
+
## Core Concepts
|
|
25
|
+
|
|
26
|
+
### Model Setup
|
|
27
|
+
|
|
28
|
+
Every model that should have media must implement `HasMedia` and use the `InteractsWithMedia` trait:
|
|
29
|
+
|
|
30
|
+
```php
|
|
31
|
+
use Spatie\MediaLibrary\HasMedia;
|
|
32
|
+
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
33
|
+
|
|
34
|
+
class BlogPost extends Model implements HasMedia
|
|
35
|
+
{
|
|
36
|
+
use InteractsWithMedia;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Adding Media
|
|
41
|
+
|
|
42
|
+
```php
|
|
43
|
+
$blogPost->addMedia($file)->toMediaCollection('images');
|
|
44
|
+
$blogPost->addMediaFromUrl($url)->toMediaCollection('images');
|
|
45
|
+
$blogPost->addMediaFromRequest('file')->toMediaCollection('images');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Defining Collections
|
|
49
|
+
|
|
50
|
+
```php
|
|
51
|
+
public function registerMediaCollections(): void
|
|
52
|
+
{
|
|
53
|
+
$this->addMediaCollection('avatar')->singleFile();
|
|
54
|
+
$this->addMediaCollection('downloads')->useDisk('s3');
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Defining Conversions
|
|
59
|
+
|
|
60
|
+
```php
|
|
61
|
+
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
62
|
+
use Spatie\Image\Enums\Fit;
|
|
63
|
+
|
|
64
|
+
public function registerMediaConversions(?Media $media = null): void
|
|
65
|
+
{
|
|
66
|
+
$this->addMediaConversion('thumb')
|
|
67
|
+
->fit(Fit::Contain, 300, 300)
|
|
68
|
+
->nonQueued();
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Retrieving Media
|
|
73
|
+
|
|
74
|
+
```php
|
|
75
|
+
$url = $model->getFirstMediaUrl('images');
|
|
76
|
+
$thumbUrl = $model->getFirstMediaUrl('images', 'thumb');
|
|
77
|
+
$allMedia = $model->getMedia('images');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Do and Don't
|
|
81
|
+
|
|
82
|
+
Do:
|
|
83
|
+
- Always implement the `HasMedia` interface alongside the `InteractsWithMedia` trait.
|
|
84
|
+
- Use `?Media $media = null` as the parameter for `registerMediaConversions()`.
|
|
85
|
+
- Call `->toMediaCollection()` to finalize adding media.
|
|
86
|
+
- Use `->nonQueued()` for conversions that should run synchronously.
|
|
87
|
+
- Use `->singleFile()` on collections that should only hold one file.
|
|
88
|
+
- Use `Spatie\Image\Enums\Fit` enum values for fit methods.
|
|
89
|
+
|
|
90
|
+
Don't:
|
|
91
|
+
- Don't forget to run `php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations"` before migrating.
|
|
92
|
+
- Don't use `env()` for disk configuration; use `config()` or set it in `config/media-library.php`.
|
|
93
|
+
- Don't call `addMedia()` without calling `toMediaCollection()` — the media won't be saved.
|
|
94
|
+
- Don't reference conversion names that aren't registered in `registerMediaConversions()`.
|
|
95
|
+
|
|
96
|
+
# Laravel Media Library Reference
|
|
97
|
+
|
|
98
|
+
Complete reference for `spatie/laravel-medialibrary`. Full documentation: https://spatie.be/docs/laravel-medialibrary
|
|
99
|
+
|
|
100
|
+
## Model Setup
|
|
101
|
+
|
|
102
|
+
Implement `HasMedia` and use `InteractsWithMedia`:
|
|
103
|
+
|
|
104
|
+
```php
|
|
105
|
+
use Illuminate\Database\Eloquent\Model;
|
|
106
|
+
use Spatie\MediaLibrary\HasMedia;
|
|
107
|
+
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
108
|
+
|
|
109
|
+
class BlogPost extends Model implements HasMedia
|
|
110
|
+
{
|
|
111
|
+
use InteractsWithMedia;
|
|
112
|
+
|
|
113
|
+
public function registerMediaCollections(): void
|
|
114
|
+
{
|
|
115
|
+
$this->addMediaCollection('images');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public function registerMediaConversions(?Media $media = null): void
|
|
119
|
+
{
|
|
120
|
+
$this->addMediaConversion('thumb')
|
|
121
|
+
->fit(Fit::Contain, 300, 300);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Adding Media
|
|
127
|
+
|
|
128
|
+
### From uploaded file
|
|
129
|
+
|
|
130
|
+
```php
|
|
131
|
+
$model->addMedia($request->file('image'))->toMediaCollection('images');
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### From request (shorthand)
|
|
135
|
+
|
|
136
|
+
```php
|
|
137
|
+
$model->addMediaFromRequest('image')->toMediaCollection('images');
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### From URL
|
|
141
|
+
|
|
142
|
+
```php
|
|
143
|
+
$model->addMediaFromUrl('https://example.com/image.jpg')->toMediaCollection('images');
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### From string content
|
|
147
|
+
|
|
148
|
+
```php
|
|
149
|
+
$model->addMediaFromString('raw content')->usingFileName('file.txt')->toMediaCollection('files');
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### From base64
|
|
153
|
+
|
|
154
|
+
```php
|
|
155
|
+
$model->addMediaFromBase64($base64Data)->usingFileName('photo.jpg')->toMediaCollection('images');
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### From stream
|
|
159
|
+
|
|
160
|
+
```php
|
|
161
|
+
$model->addMediaFromStream($stream)->usingFileName('file.pdf')->toMediaCollection('files');
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### From existing disk
|
|
165
|
+
|
|
166
|
+
```php
|
|
167
|
+
$model->addMediaFromDisk('path/to/file.jpg', 's3')->toMediaCollection('images');
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Multiple files from request
|
|
171
|
+
|
|
172
|
+
```php
|
|
173
|
+
$model->addMultipleMediaFromRequest(['images'])->each(function ($fileAdder) {
|
|
174
|
+
$fileAdder->toMediaCollection('images');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
$model->addAllMediaFromRequest()->each(function ($fileAdder) {
|
|
178
|
+
$fileAdder->toMediaCollection('images');
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Copy instead of move
|
|
183
|
+
|
|
184
|
+
```php
|
|
185
|
+
$model->copyMedia($pathToFile)->toMediaCollection('images');
|
|
186
|
+
// or
|
|
187
|
+
$model->addMedia($pathToFile)->preservingOriginal()->toMediaCollection('images');
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## FileAdder Options
|
|
191
|
+
|
|
192
|
+
All methods are chainable before calling `toMediaCollection()`:
|
|
193
|
+
|
|
194
|
+
```php
|
|
195
|
+
$model->addMedia($file)
|
|
196
|
+
->usingName('Custom Name') // display name
|
|
197
|
+
->usingFileName('custom-name.jpg') // filename on disk
|
|
198
|
+
->setOrder(3) // order within collection
|
|
199
|
+
->withCustomProperties(['alt' => 'A landscape photo'])
|
|
200
|
+
->withManipulations(['thumb' => ['filter' => 'greyscale']])
|
|
201
|
+
->withResponsiveImages() // generate responsive variants
|
|
202
|
+
->storingConversionsOnDisk('s3') // put conversions on different disk
|
|
203
|
+
->addCustomHeaders(['CacheControl' => 'max-age=31536000'])
|
|
204
|
+
->toMediaCollection('images');
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Store on cloud disk
|
|
208
|
+
|
|
209
|
+
```php
|
|
210
|
+
$model->addMedia($file)->toMediaCollectionOnCloudDisk('images');
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Media Collections
|
|
214
|
+
|
|
215
|
+
Define in `registerMediaCollections()`:
|
|
216
|
+
|
|
217
|
+
```php
|
|
218
|
+
public function registerMediaCollections(): void
|
|
219
|
+
{
|
|
220
|
+
// Basic collection
|
|
221
|
+
$this->addMediaCollection('images');
|
|
222
|
+
|
|
223
|
+
// Single file (replacing previous on new upload)
|
|
224
|
+
$this->addMediaCollection('avatar')
|
|
225
|
+
->singleFile();
|
|
226
|
+
|
|
227
|
+
// Keep only latest N items
|
|
228
|
+
$this->addMediaCollection('recent_photos')
|
|
229
|
+
->onlyKeepLatest(5);
|
|
230
|
+
|
|
231
|
+
// Specific disk
|
|
232
|
+
$this->addMediaCollection('downloads')
|
|
233
|
+
->useDisk('s3');
|
|
234
|
+
|
|
235
|
+
// With conversions disk
|
|
236
|
+
$this->addMediaCollection('photos')
|
|
237
|
+
->useDisk('s3')
|
|
238
|
+
->storeConversionsOnDisk('s3-thumbnails');
|
|
239
|
+
|
|
240
|
+
// MIME type restriction
|
|
241
|
+
$this->addMediaCollection('documents')
|
|
242
|
+
->acceptsMimeTypes(['application/pdf', 'application/zip']);
|
|
243
|
+
|
|
244
|
+
// Custom validation
|
|
245
|
+
$this->addMediaCollection('images')
|
|
246
|
+
->acceptsFile(function ($file) {
|
|
247
|
+
return $file->mimeType === 'image/jpeg';
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Fallback URL/path when collection is empty
|
|
251
|
+
$this->addMediaCollection('avatar')
|
|
252
|
+
->singleFile()
|
|
253
|
+
->useFallbackUrl('/images/default-avatar.jpg')
|
|
254
|
+
->useFallbackPath(public_path('/images/default-avatar.jpg'));
|
|
255
|
+
|
|
256
|
+
// Enable responsive images for entire collection
|
|
257
|
+
$this->addMediaCollection('hero_images')
|
|
258
|
+
->withResponsiveImages();
|
|
259
|
+
|
|
260
|
+
// Collection-specific conversions
|
|
261
|
+
$this->addMediaCollection('photos')
|
|
262
|
+
->registerMediaConversions(function () {
|
|
263
|
+
$this->addMediaConversion('card')
|
|
264
|
+
->fit(Fit::Crop, 400, 400);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Media Conversions
|
|
270
|
+
|
|
271
|
+
Define in `registerMediaConversions()`:
|
|
272
|
+
|
|
273
|
+
```php
|
|
274
|
+
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
275
|
+
use Spatie\Image\Enums\Fit;
|
|
276
|
+
|
|
277
|
+
public function registerMediaConversions(?Media $media = null): void
|
|
278
|
+
{
|
|
279
|
+
$this->addMediaConversion('thumb')
|
|
280
|
+
->fit(Fit::Contain, 300, 300)
|
|
281
|
+
->nonQueued();
|
|
282
|
+
|
|
283
|
+
$this->addMediaConversion('preview')
|
|
284
|
+
->fit(Fit::Crop, 500, 500)
|
|
285
|
+
->withResponsiveImages()
|
|
286
|
+
->queued();
|
|
287
|
+
|
|
288
|
+
$this->addMediaConversion('banner')
|
|
289
|
+
->fit(Fit::Max, 1200, 630)
|
|
290
|
+
->performOnCollections('images', 'headers')
|
|
291
|
+
->nonQueued()
|
|
292
|
+
->sharpen(10);
|
|
293
|
+
|
|
294
|
+
// Conditional conversion based on media properties
|
|
295
|
+
if ($media?->mime_type === 'image/png') {
|
|
296
|
+
$this->addMediaConversion('png-thumb')
|
|
297
|
+
->fit(Fit::Contain, 150, 150);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Keep original format instead of converting to jpg
|
|
301
|
+
$this->addMediaConversion('web')
|
|
302
|
+
->fit(Fit::Max, 800, 800)
|
|
303
|
+
->keepOriginalImageFormat();
|
|
304
|
+
|
|
305
|
+
// PDF page rendering
|
|
306
|
+
$this->addMediaConversion('pdf-preview')
|
|
307
|
+
->pdfPageNumber(1)
|
|
308
|
+
->fit(Fit::Contain, 400, 400);
|
|
309
|
+
|
|
310
|
+
// Video frame extraction
|
|
311
|
+
$this->addMediaConversion('video-thumb')
|
|
312
|
+
->extractVideoFrameAtSecond(5)
|
|
313
|
+
->fit(Fit::Crop, 300, 300);
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Image Manipulation Methods (via spatie/image)
|
|
318
|
+
|
|
319
|
+
Resizing and fitting:
|
|
320
|
+
- `width(int)`, `height(int)` — constrain dimensions
|
|
321
|
+
- `fit(Fit, int, int)` — fit within bounds using `Fit::Contain`, `Fit::Max`, `Fit::Fill`, `Fit::Stretch`, `Fit::Crop`
|
|
322
|
+
- `crop(int, int)` — crop to exact dimensions
|
|
323
|
+
|
|
324
|
+
Effects:
|
|
325
|
+
- `sharpen(int)`, `blur(int)`, `pixelate(int)`
|
|
326
|
+
- `greyscale()`, `sepia()`
|
|
327
|
+
- `brightness(int)`, `contrast(int)`, `colorize(int, int, int)`
|
|
328
|
+
|
|
329
|
+
Orientation:
|
|
330
|
+
- `orientation(int)`, `flip(string)`, `rotate(int)`
|
|
331
|
+
|
|
332
|
+
Format:
|
|
333
|
+
- `format(string)` — `'jpg'`, `'png'`, `'webp'`, `'avif'`
|
|
334
|
+
- `quality(int)` — 1-100
|
|
335
|
+
|
|
336
|
+
Other:
|
|
337
|
+
- `border(int, string, string)`, `watermark(string)`
|
|
338
|
+
- `optimize()`, `nonOptimized()`
|
|
339
|
+
|
|
340
|
+
### Conversion Configuration
|
|
341
|
+
|
|
342
|
+
- `performOnCollections('col1', 'col2')` — limit to specific collections
|
|
343
|
+
- `queued()` / `nonQueued()` — run async or sync
|
|
344
|
+
- `withResponsiveImages()` — also generate responsive variants for this conversion
|
|
345
|
+
- `keepOriginalImageFormat()` — preserve png/webp/gif instead of converting to jpg
|
|
346
|
+
- `pdfPageNumber(int)` — which PDF page to render
|
|
347
|
+
- `extractVideoFrameAtSecond(int)` — video thumbnail timing
|
|
348
|
+
|
|
349
|
+
## Retrieving Media
|
|
350
|
+
|
|
351
|
+
### Getting media items
|
|
352
|
+
|
|
353
|
+
```php
|
|
354
|
+
$media = $model->getMedia('images'); // all in collection
|
|
355
|
+
$first = $model->getFirstMedia('images'); // first item
|
|
356
|
+
$last = $model->getLastMedia('images'); // last item
|
|
357
|
+
$has = $model->hasMedia('images'); // boolean check
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Getting URLs
|
|
361
|
+
|
|
362
|
+
```php
|
|
363
|
+
$url = $model->getFirstMediaUrl('images'); // original URL
|
|
364
|
+
$thumbUrl = $model->getFirstMediaUrl('images', 'thumb'); // conversion URL
|
|
365
|
+
$lastUrl = $model->getLastMediaUrl('images', 'thumb');
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Getting paths
|
|
369
|
+
|
|
370
|
+
```php
|
|
371
|
+
$path = $model->getFirstMediaPath('images');
|
|
372
|
+
$thumbPath = $model->getFirstMediaPath('images', 'thumb');
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Temporary URLs (S3)
|
|
376
|
+
|
|
377
|
+
```php
|
|
378
|
+
$tempUrl = $model->getFirstTemporaryUrl(
|
|
379
|
+
now()->addMinutes(30),
|
|
380
|
+
'images',
|
|
381
|
+
'thumb'
|
|
382
|
+
);
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Fallback URLs
|
|
386
|
+
|
|
387
|
+
```php
|
|
388
|
+
$url = $model->getFallbackMediaUrl('avatar');
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### From the Media model
|
|
392
|
+
|
|
393
|
+
```php
|
|
394
|
+
$media = $model->getFirstMedia('images');
|
|
395
|
+
|
|
396
|
+
$media->getUrl(); // original URL
|
|
397
|
+
$media->getUrl('thumb'); // conversion URL
|
|
398
|
+
$media->getPath(); // disk path
|
|
399
|
+
$media->getFullUrl(); // full URL with domain
|
|
400
|
+
$media->getTemporaryUrl(now()->addMinutes(30));
|
|
401
|
+
$media->hasGeneratedConversion('thumb'); // check if conversion exists
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Filtering media
|
|
405
|
+
|
|
406
|
+
```php
|
|
407
|
+
$media = $model->getMedia('images', function (Media $media) {
|
|
408
|
+
return $media->getCustomProperty('featured') === true;
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
$media = $model->getMedia('images', ['mime_type' => 'image/jpeg']);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## Custom Properties
|
|
415
|
+
|
|
416
|
+
Store arbitrary metadata on media items:
|
|
417
|
+
|
|
418
|
+
```php
|
|
419
|
+
// When adding
|
|
420
|
+
$model->addMedia($file)
|
|
421
|
+
->withCustomProperties([
|
|
422
|
+
'alt' => 'Descriptive text',
|
|
423
|
+
'credits' => 'Photographer Name',
|
|
424
|
+
])
|
|
425
|
+
->toMediaCollection('images');
|
|
426
|
+
|
|
427
|
+
// Get/set on existing media
|
|
428
|
+
$media->setCustomProperty('alt', 'Updated text');
|
|
429
|
+
$media->save();
|
|
430
|
+
|
|
431
|
+
$alt = $media->getCustomProperty('alt');
|
|
432
|
+
$has = $media->hasCustomProperty('alt');
|
|
433
|
+
$media->forgetCustomProperty('alt');
|
|
434
|
+
$media->save();
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Responsive Images
|
|
438
|
+
|
|
439
|
+
Generate multiple sizes for optimal loading:
|
|
440
|
+
|
|
441
|
+
```php
|
|
442
|
+
// On the FileAdder
|
|
443
|
+
$model->addMedia($file)
|
|
444
|
+
->withResponsiveImages()
|
|
445
|
+
->toMediaCollection('images');
|
|
446
|
+
|
|
447
|
+
// On a conversion
|
|
448
|
+
$this->addMediaConversion('hero')
|
|
449
|
+
->fit(Fit::Max, 1200, 800)
|
|
450
|
+
->withResponsiveImages();
|
|
451
|
+
|
|
452
|
+
// On a collection
|
|
453
|
+
$this->addMediaCollection('photos')
|
|
454
|
+
->withResponsiveImages();
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Using in Blade
|
|
458
|
+
|
|
459
|
+
```blade
|
|
460
|
+
{{-- Renders img tag with srcset --}}
|
|
461
|
+
{{ $media->toHtml() }}
|
|
462
|
+
|
|
463
|
+
{{-- With attributes --}}
|
|
464
|
+
{{ $media->img()->attributes(['class' => 'w-full', 'alt' => 'Photo']) }}
|
|
465
|
+
|
|
466
|
+
{{-- Get srcset string --}}
|
|
467
|
+
<img src="{{ $media->getUrl() }}" srcset="{{ $media->getSrcset() }}" />
|
|
468
|
+
|
|
469
|
+
{{-- Responsive conversion --}}
|
|
470
|
+
<img src="{{ $media->getUrl('hero') }}" srcset="{{ $media->getSrcset('hero') }}" />
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Placeholder SVG
|
|
474
|
+
|
|
475
|
+
```php
|
|
476
|
+
$svg = $media->responsiveImages()->getPlaceholderSvg(); // tiny blurred base64 placeholder
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## Managing Media
|
|
480
|
+
|
|
481
|
+
### Clear a collection
|
|
482
|
+
|
|
483
|
+
```php
|
|
484
|
+
$model->clearMediaCollection('images');
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
### Clear except specific items
|
|
488
|
+
|
|
489
|
+
```php
|
|
490
|
+
$model->clearMediaCollectionExcept('images', $mediaToKeep);
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
### Delete specific media
|
|
494
|
+
|
|
495
|
+
```php
|
|
496
|
+
$model->deleteMedia($mediaId);
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Delete all media
|
|
500
|
+
|
|
501
|
+
```php
|
|
502
|
+
$model->deleteAllMedia();
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Delete model but keep media files
|
|
506
|
+
|
|
507
|
+
```php
|
|
508
|
+
$model->deletePreservingMedia();
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### Reorder media
|
|
512
|
+
|
|
513
|
+
```php
|
|
514
|
+
Media::setNewOrder([3, 1, 2]); // media IDs in desired order
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### Move/copy media between models
|
|
518
|
+
|
|
519
|
+
```php
|
|
520
|
+
$media->move($otherModel, 'images');
|
|
521
|
+
$media->copy($otherModel, 'images');
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
## Events
|
|
525
|
+
|
|
526
|
+
```php
|
|
527
|
+
use Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAddedEvent;
|
|
528
|
+
use Spatie\MediaLibrary\Conversions\Events\ConversionWillStartEvent;
|
|
529
|
+
use Spatie\MediaLibrary\Conversions\Events\ConversionHasBeenCompletedEvent;
|
|
530
|
+
use Spatie\MediaLibrary\MediaCollections\Events\CollectionHasBeenClearedEvent;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Listen to these events to hook into the media lifecycle:
|
|
534
|
+
```php
|
|
535
|
+
Event::listen(MediaHasBeenAddedEvent::class, function ($event) {
|
|
536
|
+
$event->media; // the added Media model
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
Event::listen(ConversionHasBeenCompletedEvent::class, function ($event) {
|
|
540
|
+
$event->media;
|
|
541
|
+
$event->conversion;
|
|
542
|
+
});
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
## Configuration
|
|
546
|
+
|
|
547
|
+
Key `config/media-library.php` options:
|
|
548
|
+
|
|
549
|
+
```php
|
|
550
|
+
return [
|
|
551
|
+
'disk_name' => 'public', // default disk
|
|
552
|
+
'max_file_size' => 1024 * 1024 * 10, // 10MB
|
|
553
|
+
'queue_connection_name' => '', // queue connection
|
|
554
|
+
'queue_name' => '', // queue name
|
|
555
|
+
'queue_conversions_by_default' => true, // queue conversions
|
|
556
|
+
'media_model' => Spatie\MediaLibrary\MediaCollections\Models\Media::class,
|
|
557
|
+
'file_namer' => Spatie\MediaLibrary\Support\FileNamer\DefaultFileNamer::class,
|
|
558
|
+
'path_generator' => Spatie\MediaLibrary\Support\PathGenerator\DefaultPathGenerator::class,
|
|
559
|
+
'url_generator' => Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator::class,
|
|
560
|
+
'image_driver' => 'gd', // 'gd', 'imagick', or 'vips'
|
|
561
|
+
'image_optimizers' => [/* optimizer config */],
|
|
562
|
+
'version_urls' => true, // cache busting
|
|
563
|
+
'default_loading_attribute_value' => null, // 'lazy' for lazy loading
|
|
564
|
+
];
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
### Custom Path Generator
|
|
568
|
+
|
|
569
|
+
```php
|
|
570
|
+
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator;
|
|
571
|
+
|
|
572
|
+
class CustomPathGenerator implements PathGenerator
|
|
573
|
+
{
|
|
574
|
+
public function getPath(Media $media): string
|
|
575
|
+
{
|
|
576
|
+
return md5($media->id) . '/';
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
public function getPathForConversions(Media $media): string
|
|
580
|
+
{
|
|
581
|
+
return $this->getPath($media) . 'conversions/';
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
public function getPathForResponsiveImages(Media $media): string
|
|
585
|
+
{
|
|
586
|
+
return $this->getPath($media) . 'responsive/';
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Custom File Namer
|
|
592
|
+
|
|
593
|
+
```php
|
|
594
|
+
use Spatie\MediaLibrary\Support\FileNamer\FileNamer;
|
|
595
|
+
|
|
596
|
+
class CustomFileNamer extends FileNamer
|
|
597
|
+
{
|
|
598
|
+
public function originalFileName(string $fileName): string
|
|
599
|
+
{
|
|
600
|
+
return Str::slug(pathinfo($fileName, PATHINFO_FILENAME));
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
public function conversionFileName(string $fileName, Conversion $conversion): string
|
|
604
|
+
{
|
|
605
|
+
return $this->originalFileName($fileName) . '-' . $conversion->getName();
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
public function responsiveFileName(string $fileName): string
|
|
609
|
+
{
|
|
610
|
+
return pathinfo($fileName, PATHINFO_FILENAME);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Custom Media Model
|
|
616
|
+
|
|
617
|
+
```php
|
|
618
|
+
use Spatie\MediaLibrary\MediaCollections\Models\Media as BaseMedia;
|
|
619
|
+
|
|
620
|
+
class Media extends BaseMedia
|
|
621
|
+
{
|
|
622
|
+
// Add custom methods, scopes, or override behavior
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
Register in config: `'media_model' => App\Models\Media::class`
|
|
627
|
+
|
|
628
|
+
## Downloading Media
|
|
629
|
+
|
|
630
|
+
### Single file
|
|
631
|
+
|
|
632
|
+
```php
|
|
633
|
+
return $media->toResponse($request); // download
|
|
634
|
+
return $media->toInlineResponse($request); // display inline
|
|
635
|
+
return $media->stream(); // stream
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### ZIP download of collection
|
|
639
|
+
|
|
640
|
+
```php
|
|
641
|
+
use Spatie\MediaLibrary\Support\MediaStream;
|
|
642
|
+
|
|
643
|
+
return MediaStream::create('photos.zip')
|
|
644
|
+
->addMedia($model->getMedia('images'));
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
## Using with API Resources
|
|
648
|
+
|
|
649
|
+
```php
|
|
650
|
+
class PostResource extends JsonResource
|
|
651
|
+
{
|
|
652
|
+
public function toArray($request): array
|
|
653
|
+
{
|
|
654
|
+
return [
|
|
655
|
+
'id' => $this->id,
|
|
656
|
+
'title' => $this->title,
|
|
657
|
+
'image' => $this->getFirstMediaUrl('images'),
|
|
658
|
+
'thumb' => $this->getFirstMediaUrl('images', 'thumb'),
|
|
659
|
+
'media' => $this->getMedia('images')->map(function ($media) {
|
|
660
|
+
return [
|
|
661
|
+
'id' => $media->id,
|
|
662
|
+
'url' => $media->getUrl(),
|
|
663
|
+
'thumb' => $media->getUrl('thumb'),
|
|
664
|
+
'name' => $media->name,
|
|
665
|
+
'size' => $media->size,
|
|
666
|
+
'type' => $media->mime_type,
|
|
667
|
+
];
|
|
668
|
+
}),
|
|
669
|
+
];
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
```
|