🏭 An easy way to generate populated factories for models.

Overview

Laravel Populated Factory

Laravel Populated Factory provides an easy way to generate populated factories for models according to types & names of their columns.

Install

You can install this package via composer using this command:

composer require --dev coderello/laravel-populated-factory

The package will automatically register itself.

Usage

The only thing you need to do in order to generate a populated factory is to execute this command:

php artisan make:populated-factory User

This command assumes that the User model is in the App namespace. If your models are situated in another namespace (e.g. App\Models) you should specify them either as Models\\User or \\App\\Models\\User.

Here is the populated factory generated for the User model according to its column types & names.



use Faker\Generator as Faker;

/** @var $factory \Illuminate\Database\Eloquent\Factory */

$factory->define(\App\User::class, function (Faker $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->unique()->safeEmail,
        'email_verified_at' => $faker->dateTime,
        'password' => '$2y$10$uTDnsRa0h7wLppc8/vB9C.YqsrAZwhjCgLWjcmpbndTmyo1k5tbRC',
        'remember_token' => $faker->sha1,
        'created_at' => $faker->dateTime,
        'updated_at' => $faker->dateTime,
    ];
});

If you want a custom name for the factory, you need to pass it as the second argument like so:

php artisan make:populated-factory User AdminFactory

If you want to override the existent factory, you need to use --force flag like so:

php artisan make:populated-factory User --force

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A simple way to generate files from stubs.

STUBBY A simple way to generate files from stubs. Usage For example we have a stub file that looks like this: ?php namespace {{ namespace }}; use A

Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords.

Laravel Otpify 🔑 Introduction Otpify is a Laravel package that provides a simple and elegant way to generate and validate one time passwords. Install

Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model-myPoint = new Point(1,2); //lat

Laravel Serializable Closure provides an easy way to serialize closures in PHP.

Serializable Closure Introduction This package is a work in progress Laravel Serializable Closure provides an easy way to serialize closures in PHP. I

An easy way to integrate Google Maps with Laravel

An easy way to integrate Google Maps with Laravel For Laravel 5.x, check version 2.35.1 For Laravel 4.x, check version 1.27.0 Think of Googlmapper as

Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.

Introduction Breadcrumbs display a list of links indicating the position of the current page in the whole site hierarchy. For example, breadcrumbs lik

An easy way to add colors in your CLI scripts.
An easy way to add colors in your CLI scripts.

COLORS Here is a preview of what you can achieve with the library: Installation Installation via composer is highly recommended. { "require": {

An easy way to get vendor and package data from Packagist via API calls
An easy way to get vendor and package data from Packagist via API calls

Laravel Packagist Laravel Packagist (LaravelPackagist) is a package for Laravel 5 to interact with the packagist api quickly and easily. Table of cont

Comments
Owner
Coderello
Open-source organization founded by @hivokas which offers numerous open-source packages for Laravel & JavaScript.
Coderello
Generate trends for your models. Easily generate charts or reports.

Laravel Trend Generate trends for your models. Easily generate charts or reports. Support us Like our work? You can support us by purchasing one of ou

Flowframe 139 Dec 27, 2022
Guess attributes for Laravel model factories

Eloquent Populator This package provides default attributes for Laravel model factories by guessing the best Faker formatters from columns' names and

Guido Cella 68 Aug 11, 2022
The package lets you generate TypeScript interfaces from your Laravel models.

Laravel TypeScript The package lets you generate TypeScript interfaces from your Laravel models. Introduction Say you have a model which has several p

Boris Lepikhin 296 Dec 24, 2022
A package to generate YouTube-like IDs for Eloquent models

Laravel Hashids This package provides a trait that will generate hashids when saving any Eloquent model. Hashids Hashids is a small package to generat

ΛÐģi 25 Aug 31, 2022
Generate previous attributes when saving Eloquent models

This package provides a trait that will generate previous attributes when saving any Eloquent model.

Ricardo Sawir 33 Nov 6, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Jan 7, 2023
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Eric Tucker 1.5k Dec 30, 2022
Kalibrant - a package that provides a simple way to manage your models settings

Introduction For your laravel 9.x applications, Kalibrant is a package that provides a simple way to manage your models settings. It is a simple way t

Starfolk 3 Jun 18, 2022
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 28 Dec 19, 2022
Generate form validators for Laravel: an extension of way/generators

Laravel Form Validator Contents Introduction Installation Usage Example Tests Introduction After using Jeffrey Way's Generator and his Validator packa

John Evans 6 Jan 14, 2022