goez/laravel-fakedown

A Laravel package for generating fake Markdown content

0.2.0 2025-06-13 11:25 UTC

This package is auto-updated.

Last update: 2025-06-13 13:22:42 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Installs

Laravel Fakedown is a Laravel package that generates fake Markdown content, perfect for testing, prototyping, or content placeholders.

Features

  • πŸš€ Easy to Use: Generate rich Markdown content with just a few lines of code
  • 🌍 Multi-language Support: Traditional Chinese, Simplified Chinese, English, Japanese
  • 🎨 Multiple Styles: Professional, casual, technical styles, plus domain-specific styles for music, art, technology, gaming, sports, travel, food, health, education, business, and software development
  • πŸ“ Rich Formatting: Headings, paragraphs, lists, code blocks, tables, blockquotes, links, images
  • ⚑ Artisan Commands: Convenient command-line tools
  • πŸ”§ Faker Integration: Use in data seeding, Factory, Seeder
  • πŸ“ Highly Customizable: Customize content length, language, and structure
  • πŸ§ͺ Complete Testing: Unit and integration tests

Requirements

  • PHP 8.2 or higher
  • Laravel 11.0 or higher (including Laravel 12.x and future versions)

Installation

composer require goez/laravel-fakedown

Publishing Configuration Files (Optional)

# Publish main configuration file
php artisan vendor:publish --tag=fakedown-config

# Publish template configuration file
php artisan vendor:publish --tag=fakedown-templates

# Publish all configuration files
php artisan vendor:publish --tag=fakedown-all

# Or use provider name
php artisan vendor:publish --provider="Goez\LaravelFakedown\FakedownServiceProvider"

Configuration File Description

  • config/fakedown.php: Main configuration file containing basic settings like language, length, style
  • config/fakedown-templates.php: Template content file containing all language and style template data

Usage Recommendations

  • If you only need to adjust basic settings (like default language, length), just publish fakedown-config
  • If you need to customize template content or add styles, publish fakedown-templates
  • For first-time use, recommended to publish all files: --tag=fakedown-all

Basic Usage

1. Using Facade

use Goez\LaravelFakedown\Facades\Fakedown;

// Generate basic Markdown content
$markdown = Fakedown::generate();

// Generate content with specific language, length and style
$markdown = Fakedown::generate([
    'language' => 'en',
    'length' => 5,
    'style' => 'music'  // Music style
]);

// Supported styles
$styles = [
    'professional',  // Professional style
    'casual',       // Casual style  
    'technical',    // Technical style
    'music',        // Music style
    'art',          // Art style
    'technology',   // Technology style
    'gaming',       // Gaming style
    'sports',       // Sports style
    'travel',       // Travel style
    'food',         // Food style
    'health',       // Health style
    'education',    // Education style
    'business',     // Business style
    'software'      // Software development style
];

// Generate specific elements
$heading = Fakedown::heading(1, 'en');
$paragraph = Fakedown::paragraph('en');
$list = Fakedown::list();
$codeBlock = Fakedown::codeBlock();
$table = Fakedown::table();
$title = Fakedown::title('en', 'professional');  // Generate unique title

2. Dependency Injection

use Goez\LaravelFakedown\FakedownGenerator;

class DocumentController extends Controller
{
    public function generateSample(FakedownGenerator $fakedown)
    {
        $content = $fakedown->generate([
            'language' => 'en',
            'length' => 3,
            'style' => 'technology',  // Technology style
            'structure' => [
                'enable_headings' => true,
                'enable_lists' => true,
                'enable_code_blocks' => false,
                'enable_tables' => true,
                'enable_blockquotes' => true,
                'enable_links' => true,
                'enable_images' => false,
            ]
        ]);
        
        return view('document', compact('content'));
    }
}

3. Faker Provider

use Faker\Factory;

$faker = Factory::create();
$faker->addProvider(new \Goez\LaravelFakedown\FakedownProvider($faker));

// Use in Factory or Seeder
$markdown = $faker->markdown(['language' => 'en', 'length' => 4]);
$heading = $faker->markdownHeading(2, 'en');
$paragraph = $faker->markdownParagraph('ja');
$list = $faker->markdownList();
$codeBlock = $faker->markdownCodeBlock();
$table = $faker->markdownTable();
$title = $faker->markdownTitle('en', 'professional');  // Generate unique title

4. Using in Model Factory

// database/factories/PostFactory.php
use Goez\LaravelFakedown\Facades\Fakedown;

class PostFactory extends Factory
{
    public function definition(): array
    {
        return [
            'title' => fake()->sentence(),
            'content' => Fakedown::generate([
                'language' => 'en',
                'length' => fake()->numberBetween(3, 8)
            ]),
            'excerpt' => Fakedown::paragraph('en'),
        ];
    }
}

Configuration

After publishing configuration files, you can customize settings in config/fakedown.php:

return [
    // Default language
    'default_language' => 'en',
    
    // Default content length
    'default_length' => 3,
    
    // Default style
    'default_style' => 'professional',
    
    // Template configuration file path
    'templates_file' => config_path('fakedown-templates.php'),
    
    // Structure settings
    'structure' => [
        'enable_headings' => true,
        'enable_lists' => true,
        'enable_code_blocks' => true,
        'enable_tables' => true,
        'enable_blockquotes' => true,
        'enable_links' => true,
        'enable_images' => true,
    ],
];

Supported Languages

  • zh-tw - Traditional Chinese
  • zh-cn - Simplified Chinese
  • en - English
  • ja - Japanese

Supported Elements

  • Headings (H1-H6)
  • Paragraphs
  • Unordered lists
  • Code blocks
  • Tables
  • Blockquotes
  • Links
  • Images

Artisan Commands

Quickly generate Markdown content:

# Basic usage
php artisan fakedown:generate

# Specify language, length and style
php artisan fakedown:generate --language=en --length=5 --style=music

# Output to file
php artisan fakedown:generate --output=storage/sample.md --style=technology

# Disable specific elements
php artisan fakedown:generate --no-code --no-images --no-tables

# Complete example
php artisan fakedown:generate \
    --language=en \
    --length=10 \
    --style=art \
    --output=docs/sample.md \
    --no-images

Command Options

  • --language : Specify language (zh-tw, zh-cn, en, ja)
  • --length : Specify number of sections
  • --style : Specify style (professional, casual, technical, music, art, technology, gaming, sports, travel, food, health, education, business, software)
  • --output : Output file path
  • --no-headings : Disable headings
  • --no-lists : Disable lists
  • --no-code : Disable code blocks
  • --no-tables : Disable tables
  • --no-blockquotes : Disable blockquotes
  • --no-links : Disable links
  • --no-images : Disable images
  • --no-lists : Disable lists
  • --no-code : Disable code blocks
  • --no-tables : Disable tables
  • --no-blockquotes : Disable blockquotes
  • --no-links : Disable links
  • --no-images : Disable images

Title Generator Feature

Laravel Fakedown provides a powerful title generator that creates unique and coherent titles.

Features

  • Uniqueness Guarantee: Each generated title is unique and won't be repeated
  • Multiple Combination Patterns: Uses various word combinations including prefixes, subjects, objects, and suffixes
  • Smart Connections: Automatically selects appropriate connectors to ensure title fluency
  • Style Support: Supports different styles for title generation
  • Cache Management: Built-in cache mechanism with the ability to clear generated title records

Basic Usage

use Goez\LaravelFakedown\Facades\Fakedown;

// Generate a single title
$title = Fakedown::title();
echo $title; // e.g., "Deep Analysis of Frontend Development Best Practices"

// Specify language and style
$title = Fakedown::title('en', 'professional');

// Generate multiple unique titles
for ($i = 0; $i < 5; $i++) {
    echo Fakedown::title() . "\n";
}

Advanced Features

use Goez\LaravelFakedown\FakedownGenerator;

$generator = new FakedownGenerator();

// Generate titles and check cache
$title1 = $generator->title();
$title2 = $generator->title();

// View generated titles
$generatedTitles = $generator->getGeneratedTitles();
echo "Generated " . count($generatedTitles) . " titles\n";

// Clear title cache
$generator->clearTitleCache();

// Generate new title after clearing (may repeat previous titles)
$newTitle = $generator->title();

Title Combination Patterns

The title generator uses the following combination patterns:

  1. Prefix + Subject: Deep Analysis + Frontend Development
  2. Subject + Object: Frontend Development + Best Practices
  3. Prefix + Subject + Suffix: Deep Analysis + Frontend Development + Complete Manual
  4. Subject + Object + Suffix: Frontend Development + Best Practices + Practical Guide
  5. Prefix + Object: Deep Analysis + Best Practices
  6. Object + Suffix: Best Practices + Practical Guide

Connection Modes

The system intelligently selects different connection methods:

  • Direct connection: DeepAnalysisFrontendDevelopment
  • Colon connection: Deep Analysis: Frontend Development
  • "of" connection: Deep Analysis of Frontend Development
  • "and" connection: Frontend Development and Best Practices
  • Dash connection: Deep Analysis - Frontend Development

Using in Faker Provider

use Faker\Factory;

$faker = Factory::create();
$faker->addProvider(new \Goez\LaravelFakedown\FakedownProvider($faker));

$title = $faker->markdownTitle('en', 'professional');

Advanced Examples

Generate Blog Articles

$article = Fakedown::generate([
    'language' => 'en',
    'length' => 6,
    'structure' => [
        'enable_headings' => true,
        'enable_lists' => true,
        'enable_code_blocks' => true,
        'enable_tables' => false,
        'enable_blockquotes' => true,
        'enable_links' => true,
        'enable_images' => true,
    ]
]);

Generate Technical Documentation

$documentation = Fakedown::generate([
    'language' => 'en',
    'length' => 10,
    'structure' => [
        'enable_headings' => true,
        'enable_lists' => true,
        'enable_code_blocks' => true,
        'enable_tables' => true,
        'enable_blockquotes' => false,
        'enable_links' => true,
        'enable_images' => false,
    ]
]);

Development

Common Commands

# Install dependencies
composer install

# Run tests
composer test
vendor/bin/phpunit

# Check code style
composer format-test
composer lint

# Auto-fix code style
composer format

# Run examples
php examples/basic_usage.php

# Test coverage
composer test-coverage

Todo List

  • Add more language support
  • Support custom templates
  • Add Markdown output validation
  • Performance optimization
  • More content types (math formulas, flowcharts, etc.)

Testing

composer test

Code Style

This project uses Laravel Pint for code formatting:

# Check code style
composer format-test
composer lint

# Auto-fix code style
composer format

Contributing

Please see CONTRIBUTING for details.

Changelog

Please see CHANGELOG for more information what has changed recently.

License

MIT License. See License File for details.

Documentation Languages