https://github.com/stydenet/seeder
Improved seeders for Laravel 5.0 and 5.1
https://github.com/stydenet/seeder
Last synced: 10 months ago
JSON representation
Improved seeders for Laravel 5.0 and 5.1
- Host: GitHub
- URL: https://github.com/stydenet/seeder
- Owner: StydeNet
- Created: 2015-06-14T19:12:14.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-08-23T19:35:48.000Z (over 9 years ago)
- Last Synced: 2025-06-10T01:39:13.183Z (11 months ago)
- Language: PHP
- Size: 26.4 KB
- Stars: 8
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Styde Seeder
This package for [Laravel](https://laravel.com/) allow seeding your database with faker data. It is an alternative to Model Factories of Laravel 5.1. With this package you can seed a model of your application and its related models too, using the package [Faker](https://github.com/fzaninotto/Faker).
## Installation
To install through [Composer](https://getcomposer.org/):
1. Add the following instruction to the "require" object in your composer.json:
```
"styde/seeder": "^1.0"
```
or simply execute on your console:
```
composer require styde/seeder
```
Then run `composer update`.
2. After **Styde Seeder** is installed, you need to add the service provider to the `providers` array in `config/app.php`
```
'providers' => [
// ...
Styde\Seeder\SeederServiceProvider::class,
// ...
],
```
3. Then add the following to your `database/seeds/DatabaseSeeder.php`:
```
$faker->name,
'email' => $faker->email,
'password' => bcrypt('secret'),
];
}
}
```
Once you run the seed command in Laravel `php artisan db:seed` it will create 50 users with random data by default.
### Helpers
Also, you can use these two helpers when you are working with tests or `php artisan tinker`:
```
/**
* Create one instance or a collection of the given model and persist them to the database.
*
* @param string $seeder
* @param integer $total
* @param array $customValues
*
* @return mixed
*/
function seed($seeder, $total = 1, array $customValues = array())
```
For example to create 5 users `seed('User', 5)` or to create one user with specific data `seed('User', ['name' => 'John', 'email' => 'john@example.com'])`.
```
/**
* Create one instance or a collection of a given model.
*
* @param string $seeder
* @param integer $total
* @param array $customValues
*
* @return mixed
*/
function model($seeder, $total = 1, array $customValues = array())
```
With this helper you only can create an instance or collection, but will not be persisted to the database.
## About
Styde Seeder was created by [Duilio Palacios](https://twitter.com/sileence) as part of the code for the course [Crea tu primera aplicación con Laravel 5](https://styde.net/cursos/crea-tu-primera-aplicacion-con-laravel-5/) (in Spanish)