Installation
composer require brodev/viet-ipsum-bundle
Add to config/bundles.php (if using Symfony):
return [
// ...
Brodev\VietIpsumBundle\BrodevVietIpsumBundle::class => ['all' => true],
];
First Usage Inject the service into a controller or use it directly:
use Brodev\VietIpsumBundle\Service\VietIpsumGenerator;
$generator = app(VietIpsumGenerator::class);
$lorem = $generator->generate(5); // Generates 5 sentences
echo $lorem;
Basic Configuration
Check config/packages/brodev_viet_ipsum.yaml for default settings (e.g., sentence length, word count).
Generating Placeholder Content Use in views, tests, or migrations:
// Blade template
<p>{{ Brodev\VietIpsumBundle\Service\VietIpsumGenerator::generate(3) }}</p>
// Test data
$fakeUser = User::factory()->create([
'bio' => app(VietIpsumGenerator::class)->generate(2),
]);
Customizing Output Override defaults via config or service methods:
# config/packages/brodev_viet_ipsum.yaml
brodev_viet_ipsum:
sentence_count: 3
word_count_per_sentence: 10
Or dynamically:
$generator->setWordCount(15)->generate(4);
Integration with Factories
Extend Laravel’s Factory for localized fakes:
use Brodev\VietIpsumBundle\Service\VietIpsumGenerator;
$factory->define(User::class, function () {
return [
'description' => app(VietIpsumGenerator::class)->generate(1),
];
});
API Responses Return Vietnamese lorem ipsum in API error messages or mock responses:
return response()->json([
'message' => app(VietIpsumGenerator::class)->generate(1),
], 404);
Dictionary Limitations
Brodev\VietIpsumBundle\Service\WordDictionary service binding.Caching Static Content
$cacheKey = 'viet_ipsum_'.$wordCount;
return Cache::remember($cacheKey, 3600, fn() => $generator->generate($wordCount));
Symfony vs. Laravel Quirks
bundles.php.app() or dependency injection.HTML/Markdown Escaping
{{ e(app(VietIpsumGenerator::class)->generate(3)) }}
Brodev\VietIpsumBundle\DataFixtures\WordDictionaryLoader to verify available words.Brodev\VietIpsumBundle\Service\SentenceBuilder to customize grammar (e.g., force questions).\Log::debug('Generated:', ['text' => $generator->generate(1)]);
Custom Dictionaries Bind a new dictionary service:
$app->bind(VietIpsumGenerator::class, function ($app) {
$dictionary = new CustomWordDictionary();
return new VietIpsumGenerator($dictionary);
});
Add Punctuation Rules
Modify Brodev\VietIpsumBundle\Service\SentenceBuilder to support Vietnamese-specific punctuation (e.g., 「」 quotes).
Localization Hooks Trigger events before/after generation:
$generator->generate(2, function ($text) {
// Post-process text (e.g., add emojis)
return str_replace('lorem', 'lorem 🌏', $text);
});
How can I help you explore Laravel packages today?