Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lorem Ipsum Bundle Laravel Package

knpuniversity/lorem-ipsum-bundle

Symfony bundle that generates lorem ipsum placeholder text through a simple, injectable service. Useful for demos, fixtures, and tutorials, it ships with a configurable ipsum generator and an interface you can swap for your own implementation. Lightweight, easy to install via Composer.

View on GitHub
Deep Wiki
Context7

Getting Started

This is a Symfony bundle, not a Laravel package. There is no service provider, no facade, no Blade directive, and it is archived (last release March 2018). Treat it as a source of a single useful class rather than something you composer require into a Laravel app.

Do not try to install it normally. Its composer.json requires symfony/framework-bundle and Twig at versions that will not resolve against a modern Laravel install (Laravel 9+ ships Symfony 6/7 components). Composer will either fail or drag in an incompatible framework-bundle.

What to look at first (on GitHub):

  1. src/KnpUIpsum.php — the only class you actually want. It exposes roughly getWords(int $count), getSentences(int $count), and getParagraphs(int $count).
  2. src/DependencyInjection/Configuration.php — shows the two config knobs (unicorns_are_real, min_sunshine).
  3. src/Twig/KnpUIpsumExtension.php — shows how the knpu_lorem_ipsum() Twig function is wired; you will re-create this as a Blade directive.

Minimal path for a Laravel developer: copy KnpUIpsum.php into app/Support/LoremIpsum/KnpUIpsum.php, adjust the namespace, and bind it in a service provider.

// app/Providers/LoremIpsumServiceProvider.php
public function register(): void
{
    $this->app->singleton(\App\Support\LoremIpsum\KnpUIpsum::class, function () {
        return new \App\Support\LoremIpsum\KnpUIpsum();
    });
}

First use case: database seeders and factories. Instead of hardcoded 'Lorem ipsum dolor sit amet' in fifty places, inject the service and generate flavourful filler copy that is obviously fake:

// database/seeders/PostSeeder.php
$ipsum = app(\App\Support\LoremIpsum\KnpUIpsum::class);

Post::factory()->count(20)->create([
    'body' => $ipsum->getSentences(4),
]);

Implementation Patterns

1. Singleton + helper. Bind once and use app(KnpUIpsum::class) or inject via constructor. Do not new it inside loops — the constructor builds word lists.

2. Blade directive. Mirror the bundle's Twig extension with a directive so views can use it:

// in the service provider's boot()
Blade::directive('ipsum', function ($expression) {
    return "<?php echo e(app(\App\Support\LoremIpsum\KnpUIpsum::class)->getSentences($expression ?: 3)); ?>";
});
<p>@ipsum(4)</p>

3. Faker fallback inside factories. If you want it everywhere, wrap it in a Faker provider so fake() and $this->faker pick it up:

class IpsumProvider extends \Faker\Provider\Base
{
    public function unicornText(int $sentences = 3): string
    {
        return app(KnpUIpsum::class)->getSentences($sentences);
    }
}
// then: $this->faker->addProvider(new IpsumProvider($this->faker));

4. Deterministic tests. The output is random, so never assert on exact strings. Assert on shape:

$this->assertGreaterThan(50, strlen($post->body));
$this->assertStringNotContainsString('{{', $post->body);

If you need reproducibility, seed mt_srand() before generating, since the class uses mt_rand, or subclass it and override the random picker.

5. Custom vocabulary. The constructor accepts a word list (and the bundle's extension point is the KnpUWordList interface with tagged services). In Laravel, just pass your array — great for domain-specific filler ("sprockets, widgets, invoices") so demo data reads like your product:

$this->app->bind(KnpUIpsum::class, fn () => new KnpUIpsum([
    'unicorn', 'rainbow', 'sprocket', 'invoice', 'ledger',
]));

6. Demo/preview endpoints. For a staging "content preview" route, return generated paragraphs as JSON:

Route::get('/api/preview', fn () => response()->json([
    'paragraphs' => app(KnpUIpsum::class)->getParagraphs(3),
]));

7. If you genuinely want the bundle, run it in a tiny Symfony sidecar (console command or HTTP microservice) and call it from Laravel over HTTP/CLI. That is more infrastructure than the joke output is worth — copying the class is the pragmatic answer.

Gotchas and Tips

  • Archived and unmaintained. No security patches, no PHP 8.2+ testing guarantee. Read the class before trusting it; it is short (a few dozen lines) and uses basic mt_rand/array_rand calls.
  • Package identity confusion. It is knpuniversity/lorem-ipsum-bundle; the namespace is KnpU\LoremIpsumBundle. Renaming the namespace when copying is mandatory — a stale use KnpU\LoremIpsumBundle\KnpUIpsum; will fatal on autoload.
  • Return types differ per method. Verify before assuming: getWords()/getSentences() return strings, while getParagraphs() returns an array of strings. implode("\n\n", ...) it if you need a blob for a DB column.
  • The config keys are jokes with real effects. unicorns_are_real and min_sunshine in the Symfony extension change which word list is used. In your copy, hardcode the behaviour or convert them to a config/lorem.php file — do not leave dead parameters hanging around.
  • No Twig means no extension. The knpu_lorem_ipsum() Twig function will never exist in Laravel; you must supply the Blade directive yourself or call the service from the controller.
  • Seeding performance. Generating hundreds of thousands of rows through PHP string concatenation is slow. Cap factory counts or generate one paragraph and reuse it in bulk inserts.
  • Escaping. The generator can emit punctuation and occasional HTML-ish characters depending on your custom word list. Always pass output through e()/Blade escaping; never {!! !!} generated text.
  • Extension points that survive the copy: the constructor word list and a subclass overriding the random selection. The Symfony service tag / DI compiler pass does not, so do not port it.
  • Debugging tip: if output looks truncated or empty, check the count argument — the class tends to loop on $count and small/zero values produce surprising results, especially with short custom word lists.
  • Honest alternative: fakerphp/faker's realText() and text() already do this, are maintained, ship with Laravel, and are faster. Use this package only if the unicorn/rainbow flavour is genuinely the point (demos, talks, internal tooling).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin