Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sheets Laravel Package

spatie/sheets

Spatie Sheets lets Laravel apps store and retrieve static content from plain text files. Markdown and front matter work out of the box, with flexible parsing, multiple content collections, indexing, and Eloquent-like casting—ideal for docs sites and blogs.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Content Management Layer: Ideal for decoupling static content (e.g., documentation, marketing pages, or blog posts) from the database, reducing schema complexity and improving performance for read-heavy use cases.
  • Hybrid CMS Approach: Complements Laravel’s Eloquent ORM by offering a lightweight, file-based alternative for content that doesn’t require dynamic relationships or transactions.
  • Frontend-Centric Workflows: Aligns with modern static site generation (SSG) patterns (e.g., Markdown + front matter) while retaining Laravel’s templating (Blade) and routing flexibility.
  • Microservice Potential: Could serve as a standalone content API (via Laravel’s HTTP layer) for headless architectures, though this would require additional abstraction.

Integration Feasibility

  • Low Friction: Leverages Laravel’s built-in filesystem (e.g., Storage facade) and service container, requiring minimal configuration.
  • Format Agnosticism: Supports custom parsers (e.g., YAML, JSON, or even CSV) via the Parser contract, enabling reuse for non-Markdown content (e.g., configuration files).
  • Collection Isolation: Collections (e.g., posts, docs) map cleanly to Laravel’s module patterns or even separate directories, aiding organization.
  • Caching: Integrates with Laravel’s cache layer (e.g., cache()->remember()) for performance, though the package itself doesn’t enforce this.

Technical Risk

  • File System Dependencies:
    • Risk: File-based storage introduces race conditions (e.g., concurrent writes) or permission issues if not managed (e.g., using storage:link or cloud storage adapters).
    • Mitigation: Use Laravel’s filesystem drivers (S3, local, etc.) with proper locking (e.g., Storage::lock()) or queue delayed writes.
  • Content Validation:
    • Risk: No built-in schema validation for front matter or custom formats, leading to runtime parsing errors.
    • Mitigation: Implement custom parsers with validation (e.g., using spatie/array-to-object or symfony/yaml with constraints).
  • SEO/URL Management:
    • Risk: Dynamic routes (e.g., /:id) may conflict with existing Laravel routes or require manual slug generation.
    • Mitigation: Use Laravel’s route model binding with a Sheet facade or middleware to resolve IDs to files.
  • Performance at Scale:
    • Risk: Large collections (e.g., 10K+ files) may slow down Sheets::all() or indexing.
    • Mitigation: Implement lazy loading or database-backed indexes for metadata (e.g., store title, updated_at in a sheets_metadata table).

Key Questions

  1. Use Case Alignment:
    • Is the content truly static, or does it require dynamic updates (e.g., user-generated content)? If the latter, consider hybrid approaches (e.g., sync files to a sheets table via a SheetsObserver).
  2. Deployment Workflow:
    • How will content be authored? Direct file edits (risk of version control bloat) vs. a CMS (e.g., Strapi + Sheets as a cache layer)?
  3. Localization/Translations:
    • Does the package support multi-language content? If so, how will translations be structured (e.g., sheets/en/posts/, sheets/es/posts/)? Custom parsers may be needed.
  4. Backup/Disaster Recovery:
    • File-based storage requires explicit backup strategies (e.g., include storage/app/sheets in Laravel Forge/Envoyer backups).
  5. Testing Strategy:
    • How will you test content changes? Mock the Sheets facade or use a temporary filesystem (e.g., Storage::fake()).
  6. Extensibility Needs:
    • Are there plans to add features like diffing, versioning, or access control? The package’s simplicity may require forks or wrappers.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Core: Works seamlessly with Laravel 10+ (tested up to the last release). No PHP version constraints beyond Laravel’s requirements.
    • Extensions:
      • Markdown: Pairs well with spatie/laravel-markdown or parsedown/parsedown for advanced rendering.
      • Front Matter: Compatible with spatie/laravel-frontmatter for shared parsing logic.
      • Caching: Integrate with spatie/laravel-caching or Redis for high-traffic sites.
      • APIs: Can serve as a content layer for Laravel Sanctum/Passport APIs or GraphQL (via Lighthouse).
  • Non-Laravel:
    • Standalone PHP: Possible with minor adjustments (e.g., mocking the service container), but loses Laravel-specific features (e.g., filesystem drivers, Blade).

Migration Path

  1. Pilot Phase:
    • Start with a single collection (e.g., docs) to validate the workflow.
    • Use existing Markdown files (e.g., from a resources/markdown directory) and migrate them to the package’s storage path.
  2. Incremental Adoption:
    • Replace static Blade templates with Sheets::get() calls for non-dynamic content.
    • Gradually move database-backed content (e.g., blog posts) to files if updates are infrequent.
  3. Hybrid Pattern:
    • Use a SheetsService to abstract file/database access:
      class ContentService {
          public function get(string $id, bool $fromFiles = true) {
              return $fromFiles ? Sheets::get($id) : Post::findOrFail($id);
          }
      }
      
  4. Tooling:
    • IDE Support: Configure PHPStorm/VSCode to treat .md files as templates (e.g., Blade syntax highlighting).
    • CI/CD: Add a step to validate Markdown files (e.g., using laravel-markdown-validator).

Compatibility

  • Laravel Versions: Tested on Laravel 10+; may require minor adjustments for older versions (e.g., dependency updates).
  • Filesystem Drivers: Supports all Laravel drivers (local, S3, FTP), but cloud storage may need tuning for performance (e.g., CDN caching).
  • Custom Parsers: Extend the Parser interface to support non-Markdown formats (e.g., JSON for configs):
    class JsonParser implements Parser {
        public function parse(string $contents): array {
            return json_decode($contents, true);
        }
    }
    
  • Route Conflicts: Ensure route namespaces (e.g., sheets.web) avoid collisions with existing routes.

Sequencing

  1. Setup:
    • Install: composer require spatie/sheets.
    • Publish config: php artisan vendor:publish --tag=sheets-config.
    • Configure storage path (e.g., storage/app/sheets).
  2. Content Migration:
    • Create a sheets directory structure (e.g., sheets/posts/, sheets/docs/).
    • Convert existing content to Markdown with front matter.
  3. Routing:
    • Define routes for collections (e.g., Route::get('/docs/{id}', [SheetController::class, 'show'])).
    • Use Laravel’s route caching (php artisan route:cache) for production.
  4. Caching:
    • Implement application-level caching for Sheets::get() calls:
      $sheet = Cache::remember("sheet:{$id}", now()->addHours(1), fn() => Sheets::get($id));
      
  5. Monitoring:
    • Log file operations (e.g., Sheets::get() calls) to track performance.
    • Set up alerts for filesystem errors (e.g., disk full).

Operational Impact

Maintenance

  • Pros:
    • No Database Migrations: Content changes don’t require schema updates.
    • Version Control: Files are trackable via Git (e.g., git add storage/app/sheets/).
    • Simplified Backups: Backup the storage directory (or cloud bucket) instead of a database.
  • Cons:
    • Manual Updates: No built-in admin interface (though tools like spatie/laravel-medialibrary could inspire a file manager).
    • Permission Management: Filesystem permissions must be configured (e.g., chmod -R 755 storage/app/sheets).
    • Dependency Updates: Monitor for breaking changes in Laravel’s filesystem or parsing libraries.

Support

  • Debugging:
    • File Not Found: Verify the storage path and file permissions.
    • Parsing Errors: Check front matter syntax (e.g., YAML validation) or custom parser logic.
    • Performance: Use Laravel’s debugbar to profile Sheets::get() calls.
  • Community:
    • Limited direct support (MIT license, no official maintainer), but Spatie’s other packages (e.g., laravel-permission) have active communities.
    • GitHub issues are responsive for bugs (302 stars suggest moderate adoption).
  • Documentation:
    • README is clear but lacks advanced scenarios (e.g., custom parsers, multi-language setups). Contribute examples or internal docs.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport