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

Faker Pictwo Laravel Package

toneflix/faker-pictwo

A Faker provider for Laravel and PHP that generates placeholder image URLs from Picsum. Add realistic photo placeholders to factories and seeders with configurable width, height, grayscale, blur, and seed options, without storing any local image files.

View on GitHub
Deep Wiki
Context7

Getting Started

toneflix/php-faker-pictwo is a PHP Faker provider, not a Laravel service provider. That distinction drives everything about how you wire it up: there is no auto-discovery, no config file to publish, and no facade. You hand an instance to Faker's generator and then call its methods like any other formatter ($faker->name(), $faker->city(), …).

1. Install

composer require toneflix/php-faker-pictwo:^2.1

Pin to ^2.1.1 or later — see the Gotchas section for why 2.0.0 is not a safe floor if you use category whitelisting.

2. Register it once, centrally

Laravel binds Faker\Generator as a singleton (via DatabaseServiceProvider), and the fake() helper resolves that same instance. Hook into the resolution in AppServiceProvider::boot() so every factory, seeder, and fake() call gets the extra formatters:

use Faker\Generator;
use Toneflix\FakerPictwo\Provider;

public function boot(): void
{
    $this->app->afterResolving(Generator::class, function (Generator $faker) {
        $faker->addProvider(new Provider($faker));
    });
}

If you prefer zero global mutation, add the provider inside the factories that need it instead ($this->faker->addProvider(new Provider($this->faker));) — correct, just more repetitive.

3. Confirm it works before writing any seeders

php artisan tinker
>>> fake()->addProvider(new Toneflix\FakerPictwo\Provider(fake()));
>>> get_class_methods(Toneflix\FakerPictwo\Provider::class);

get_class_methods() is the fastest way to see the exact formatter names and signatures your installed version exposes — more trustworthy than a README, which is precisely what 2.1.1 had to correct.

First realistic use case: demo/seed data for a marketplace or SaaS app — project names, product titles, workspace names, tag lists, placeholder usernames. Reach for it in database/seeders and factories, not in application code paths.

Implementation Patterns

In model factories. Register in the provider (step 2 above) and the formatter is available on $this->faker like any core one:

public function definition(): array
{
    $title = $this->faker->pictwo(); // adjust to the method your version exposes

    return [
        'name' => $title,
        'slug' => Str::slug($title).'-'.Str::lower(Str::random(6)),
        'description' => $this->faker->sentence(),
    ];
}

Category-scoped generation. The category whitelist is the main lever for making output fit a domain. Restrict to the categories your UI context implies (e.g. tech-flavoured words for a dev tool, nature words for a travel app) rather than drawing from the whole pool — otherwise seeds read as noise. Check the provider source for the exact accepted shape (array of strings vs. a single string) in your installed tag.

Always slug-and-suffix anything user-visible. Word combinations are drawn from a finite list, so collisions in a unique column are a matter of seeding volume, not luck. Append a short random suffix or the model key.

Determinism when you need reproducible fixtures. Faker's seed() makes output stable for a given word-list version. Useful for screenshot tests and demo environments:

$faker = fake();
$faker->seed(20240101);

Do not rely on seeded output surviving a dependency bump — treat generated names as opaque.

Wrap it behind your own helper. Rather than sprinkling $faker->pictwo(...) across 40 factories, add one class:

final class DemoName
{
    public static function make(array $categories = []): string
    {
        return Str::title(fake()->pictwo($categories));
    }
}

When the package's API shifts (as the whitelist behaviour just did), you have one file to change instead of a codebase-wide grep.

Bulk generation in seeders. Build the array first, de-duplicate, then insert:

$names = collect(range(1, 200))
    ->map(fn () => fake()->pictwo())
    ->unique()
    ->values();

Product::insert($names->map(fn ($n) => [
    'name' => $n,
    'slug' => Str::slug($n).'-'.Str::random(5),
    'created_at' => now(),
    'updated_at' => now(),
])->all());

Composition with other providers. The output pairs well with fake()->domainWord(), fake()->userName(), or fake()->slug() for secondary fields — don't force one provider to fill every column.

Extension point. Subclass the provider and add your own category data, then register the subclass in step 2. This is the clean way to get domain vocabulary without forking the package.

Gotchas and Tips

2.0.0 → 2.1.1: the whitelist fix is the reason to upgrade. 2.1.1 is titled "fix: category whitelist and README accuracy". If you are on 2.0.0 and passing a category whitelist, your restriction was likely being ignored — you were getting the full pool while believing you had scoped it. There is no runtime error for this, which makes it a silent data-quality bug: seeds look plausible but don't match intent. Bump to ^2.1.1 and re-verify a couple of seeded rows by eye.

The README was inaccurate. The same release corrected documentation. If you copied code from the 2.0.0 README, treat those snippets as suspect — re-read the current README, and cross-check against get_class_methods() / the constructor signature in vendor/toneflix/php-faker-pictwo/src. Assume a stale blog post or AI-generated snippet is wrong until it runs.

No breaking changes in 2.1.1. It's a patch release with a bug fix and docs correction. Safe to take on any 2.x constraint; no migration, no config changes. Keep the constraint at ^2.1.1 rather than ^2.0 so the fix is guaranteed.

Don't double-register in tests. Calling addProvider() in both a base TestCase and a factory adds the provider repeatedly; Faker's formatter map just overwrites, so it's harmless but wasteful. Register once in AppServiceProvider and let tests inherit it.

unique() will throw on a small pool. Faker's unique() modifier raises OverflowException once the source is exhausted. With a narrow category whitelist and a seeder generating thousands of rows, you will hit it. Fixes, in order of preference: widen categories, add a random suffix, or catch and regenerate. Do not reach for unique() unless you've reasoned about pool size.

It is not a source of randomness for security purposes. Word-pair picking is fine for demo data and terrible for tokens, invite codes, or anything an attacker benefits from predicting. Use Str::random() / random_bytes() there.

Locale settings probably won't apply. config('app.faker_locale') drives Faker's own locale-specific providers; a word-list provider carries its own data and typically ignores it. Don't be surprised when switching locale changes names and addresses but not this formatter's output.

Debugging output that "looks wrong": dump the resolved categories and the raw array before title-casing/slugging. Nine times out of ten the bug is your formatting layer (double Str::title, aggressive slug truncation), not the provider.

Treat generated values as non-deterministic across patches. Word lists are data files that can change between releases. Never assert exact generated strings in tests — assert shape (is_string, non-empty, matches a regex, unique within the batch).

Watch the package's bus factor. This is a small, single-maintainer package. Because it's only used for seeding, keep the dependency in require-dev if you only ever call it from factories and seeders, so a future abandoned release can't affect production installs.

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.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager