Download the PHP package jcfrane/laravel-md-blog without Composer
On this page you can find all versions of the php package jcfrane/laravel-md-blog. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-md-blog
laravel-md-blog
Write blog posts as markdown files with YAML front matter. No database, no CMS — just files and a clean query API.
Built for Laravel 12+ / PHP 8.2+.
Installation
Publish the config (optional):
Usage
Writing Posts
Create .md files in resources/markdown/blog/ (configurable) with YAML front matter:
Front matter fields:
| Field | Required | Default |
|---|---|---|
title |
No | Filename |
slug |
No | Filename |
date |
No | File modification time |
tags |
No | [] |
category |
No | "" |
excerpt |
No | Generated from the body (see below) |
cover |
No | null |
published |
No | true |
Any additional front matter fields are available via $post->meta.
Excerpt. When excerpt is omitted, one is built from the first excerpt_length characters (default 160) of the body's prose. Headings and code blocks are skipped, and the cut lands on a word boundary.
Cover. cover works like an image in the body: a path relative to the blog directory (images/cover.jpg) is rewritten to the image route, while absolute URLs are kept as they are. The resolved URL is on $post->cover.
Querying Posts
All query methods return Laravel Collections (except find() which returns a Post or null, and paginate() which returns a LengthAwarePaginator). Results are newest first. Drafts (published: false) are automatically excluded.
Query Builder
For anything beyond a single filter, chain conditions on a query:
Pagination
paginate() returns a LengthAwarePaginator, so it renders in Blade with {{ $posts->links() }} and serializes for Inertia as { data, links, meta... } the same way an Eloquent paginator does:
The current page is read from the request's page query string. Pass a different name or an explicit page with paginate(9, 'p', $page).
Previous, Next and Related
Related posts are scored by shared tags (two points each) plus one point for the same category. Posts with no overlap are left out.
The Post Object
Each post is an immutable Post DTO with these properties:
Post implements Arrayable, Jsonable, and JsonSerializable for clean Inertia/API integration:
Custom Post Model
You can extend the base Post class to customize how posts are built — for example, to apply syntax highlighting to code blocks.
Set the post_class config option to your custom class:
Then create a class that extends Post and overrides the make() factory method:
The make() method receives all post attributes as an array. You can modify any of them (html, title, body, etc.) before calling parent::make() to construct the post.
Cached posts built with a different class are re-parsed automatically, so no cache clear is needed after changing post_class.
Images
The package automatically handles images stored within your blog directory.
Relative Images
If you have an image at resources/markdown/blog/images/photo.png, you can reference it in your markdown as:
The package will automatically rewrite this URL to a dedicated route that serves the image securely.
Image Configuration
By default, images are served with a long cache duration (24 hours). You can customize this in the config:
When images.enabled is true (default), the package registers a route at /{route_prefix}/images/{path} to serve your assets.
Absolute URLs (APIs, mobile apps, email)
Image URLs are root-relative by default (/md-blog/images/photo.png). That breaks as soon as the HTML leaves your web page: a mobile app reading the JSON API or an email client has no origin to resolve against. Set the base URL and every image and cover URL becomes absolute:
Rendered HTML is cached, so the base URL is baked in at parse time. Run MdBlog::clearCache() after changing it.
Send blog posts as emails to your subscribers. The feature is opt-in and disabled by default.
Setup
-
Set the environment variables:
- Implement the
EmailRecipientinterface on your model:
The ReceivesPostMail trait provides defaults for emailRecipients() (returns static::cursor()), getEmailAddress() ($this->email), and getEmailName() ($this->name). Override any of these if your model differs.
Sending
Three ways to send:
Queue Support
Enable queued sending to avoid blocking:
Customizing the Email Template
Publish the views to customize the email layout:
This copies the template to resources/views/vendor/md-blog/mail/post.blade.php.
Configuration
Caching
Posts are cached per-file with automatic staleness detection — when a file is modified, the cached entry is automatically refreshed on the next read. A slug index is cached alongside so find() opens one file instead of scanning the directory; it rebuilds itself when a file is added, moved, removed or its slug changes. Use MdBlog::clearCache() to force a full cache bust.
Development
Running Tests
Workbench (Demo App)
The package includes a workbench powered by Orchestra Testbench:
Visit http://localhost:8000/blog to see the demo blog.
License
MIT
All versions of laravel-md-blog with dependencies
illuminate/support Version ^12.0 || ^13.0
illuminate/cache Version ^12.0 || ^13.0
illuminate/mail Version ^12.0 || ^13.0
league/commonmark Version ^2.5
spatie/yaml-front-matter Version ^2.0