PHP code example of goez / laravel-fakedown

1. Go to this page and download the library: Download goez/laravel-fakedown library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

goez / laravel-fakedown example snippets


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

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'));
    }
}

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

// 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'),
        ];
    }
}

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,
    ],
];

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";
}

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();

use Faker\Factory;

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

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

$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,
    ]
]);

$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,
    ]
]);