A handy set of extra Faker Formatters/Providers for fzaninotto/faker built to integrate with Laravel or any PHP project that uses Faker.
composer install rootinc/faker-bonus --dev
We can add new Providers directly to the Faker instance before we use it:
<?php
$faker = Faker\Factory::create();
ProviderCollectionHelper::addAllProvidersTo($faker);
// Use Faker
$faker->hashtag;
<?php
$faker = Faker\Factory::create();
$faker->addProvider(new Provider\Hashtag($faker));
//...
// Add more Providers
//...
// Use Faker
$faker->hashtag;
We can have Providers/Formatters added to all instances of Faker\Generator
by updating our AppServiceProvier
as follows:
app/Providers/AppServiceProvider.php
<?php
use Faker\Generator;
public function register() {
//...
// Whenever Faker\Generator is called, substitute the return value of this block
$this->app->extend(Generator::class, function ($generator) {
// Add Providers to the Faker\Generator class
ProviderCollectionHelper::addAllProvidersTo($generator);
// Return modified Faker\Generator
return $generator;
});
//...
}
Build some fun hashtags.
$faker->hashtag($includeTag = true)
$faker->hashtag // '#this_is_fun'
$faker->hashtag(false) // 'this_is_fun'
Builds handle-ish mentions.
$faker->mention($includeAt = true)
$faker->mention // '@bartoletti.barbara'
$faker->mention(false) // 'bartoletti.barbara'
Create tweet-like text.
$faker->tweetText($nbParagraphs = 1, $includeEmoji = true)
$faker->tweetText // '@BSCHADEN The a my were anchors for consider that one man perfectly. 😀 #EXPLOIT_CUTTINGEDGE_EYEBALLS'
$faker->tweetText(2) // '@BSCHADEN The a my were anchors for consider that one man perfectly.\n\n Created, rung and over flows let four it lane.😀 #EXPLOIT_CUTTINGEDGE_EYEBALLS'
$faker->tweetText(3, false) // '@BSCHADEN The a my were anchors for consider that one man perfectly.\n\n Created, rung and over flows let four it lane.\n\n Created, rung and over flows let four it lane. #EXPLOIT_CUTTINGEDGE_EYEBALLS'
composer install
vendor/bin/phpunit
- Influenced by: mbezhanov/faker-provider-collection