spatie/yaml-front-matter
Parse YAML front matter from Markdown and similar files. Reads metadata wrapped in --- at the top and returns an object with easy access to fields (via matter() or properties) plus the remaining body content. Ideal for static pages, docs, and blogs.
Storage, Filesystem) and Eloquent models (e.g., parsing metadata for content-heavy models).Symfony/Yaml fallback).SplFileObject) may be needed for scalability.!!php/object exploits) must be mitigated via whitelisting or strict parsing.realpath() validation).YamlFrontMatter → Eloquent attributes or DTOs).public, storage, or a CDN? How will caching (e.g., Redis) handle stale metadata?tags: [tech, laravel]).Storage::disk() for file access (e.g., Storage::get('posts/post.md')).Post::addGlobalScope('YamlFrontMatter', ...)).Resource classes).symfony/yaml linter)..md, .txt, or any text file with YAML front-matter.spatie/yaml-front-matter).YamlFrontMatterParser) to encapsulate parsing logic.public function getTitleAttribute()).post:{id})./admin/posts/{id}/metadata).title: "Post" vs. title: Post).php artisan yaml:validate).parse-yaml-job) for large file batches.json column or normalize into relational tables (e.g., post_tags).title, tags).| Failure Scenario | Mitigation |
|---|---|
| Corrupt YAML | Fallback to default values or skip parsing with logging. |
| File Permissions | Ensure storage permissions (e.g., chmod -R 755 storage/) and use Storage::. |
| Memory Limits (large files) | Stream files or increase memory_limit in PHP.ini. |
| Race Conditions (file updates) | Use file locking (flock) or optimistic concurrency (e.g., updated_at). |
| Dependency Vulnerabilities | Pin package version in composer.json and monitor Spatie’s releases. |
How can I help you explore Laravel packages today?