PHPackages                             cassarco/markdown-tools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. cassarco/markdown-tools

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

cassarco/markdown-tools
=======================

A package for Laravel that lets you run Laravel Validation and/or a handler function over markdown files in your application.

v2.0.1(3mo ago)013[1 PRs](https://github.com/cassarco/markdown-tools/pulls)MITPHPPHP ^8.3CI passing

Since Mar 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/cassarco/markdown-tools)[ Packagist](https://packagist.org/packages/cassarco/markdown-tools)[ Docs](https://github.com/cassarco/markdown-tools)[ RSS](/packages/cassarco-markdown-tools/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (14)Versions (10)Used By (0)

markdown-tools
==============

[](#markdown-tools)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cc6add150828e9a741a4808a9de0b97826ddcb3e5e89eb841f3883466efacbf5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636173736172636f2f6d61726b646f776e2d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cassarco/markdown-tools)[![GitHub Tests Action Status](https://camo.githubusercontent.com/abf974501ded0ab22e43c1d881a8abe65e5e1daae31afeed85e9a9661bec2bd0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636173736172636f2f6d61726b646f776e2d746f6f6c732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/cassarco/markdown-tools/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a8dfac85db4325bc29bb6554bb2a90f79c5e43f24703d0e4a6029cff244eeda8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636173736172636f2f6d61726b646f776e2d746f6f6c732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/cassarco/markdown-tools/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/7c3ca464ce3d8bb5bcbbfd37d0f02cb20b7c9fd7c4a07a9af301b2f15357104f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636173736172636f2f6d61726b646f776e2d746f6f6c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cassarco/markdown-tools)

A Laravel package for processing markdown files with validation and custom handlers.

Why?
----

[](#why)

Markdown files with YAML front-matter are a great way to manage content. They're version-controlled, portable, and easy to edit. But when your Laravel application needs that content in the database, you need a reliable way to import it.

This package lets you:

- **Sync markdown to your database** - Import blog posts, documentation, or any content from markdown files to Eloquent models, keeping them in sync as you update your files.
- **Validate front-matter** - Use Laravel's validation rules to ensure every markdown file has the required metadata (title, slug, dates, etc.) before processing.
- **Process multiple content types** - Define separate schemes for different content types (articles, docs, pages) each with their own validation rules and handlers.
- **Automate in CI/CD** - Run the command in your deployment pipeline to automatically sync content changes.

How it works
------------

[](#how-it-works)

Define one or more schemes in your configuration file, then run the bundled command to process them.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require cassarco/markdown-tools
```

Run the install command to publish the config and action stubs:

```
php artisan markdown-tools:install
```

This publishes:

- `config/markdown-tools.php` - configuration file
- `app/Actions/MarkdownFileHandler.php` - handler for processing markdown files
- `app/Actions/MarkdownFileRules.php` - validation rules for front-matter

Alternatively, publish them separately:

```
php artisan vendor:publish --tag=markdown-tools-config
php artisan vendor:publish --tag=markdown-tools-actions
```

Configuration
-------------

[](#configuration)

The published config file defines your schemes:

```
use App\Actions\MarkdownFileHandler;
use App\Actions\MarkdownFileRules;

return [
    'schemes' => [
        'default' => [
            'path' => resource_path('markdown'),
            'rules' => MarkdownFileRules::class,
            'handler' => MarkdownFileHandler::class,
        ],
    ],

    'common-mark' => [
        // League/CommonMark settings...
    ],
];
```

Usage
-----

[](#usage)

### Define Validation Rules

[](#define-validation-rules)

Edit `app/Actions/MarkdownFileRules.php` to specify validation rules for front-matter properties:

```
