iseed

所属分类:后台框架
开发工具:PHP
文件大小:22KB
下载次数:0
上传日期:2023-05-22 09:32:30
上 传 者sh-1993
说明:  Laravel逆种子发生器
(Laravel Inverse Seed Generator)

文件列表:
.travis.yml (185, 2023-03-27)
LICENSE (1306, 2023-03-27)
composer.json (1342, 2023-03-27)
phpunit.xml (641, 2023-03-27)
src (0, 2023-03-27)
src\Orangehill (0, 2023-03-27)
src\Orangehill\Iseed (0, 2023-03-27)
src\Orangehill\Iseed\Exceptions.php (95, 2023-03-27)
src\Orangehill\Iseed\Facades (0, 2023-03-27)
src\Orangehill\Iseed\Facades\Iseed.php (295, 2023-03-27)
src\Orangehill\Iseed\Iseed.php (12584, 2023-03-27)
src\Orangehill\Iseed\IseedCommand.php (7108, 2023-03-27)
src\Orangehill\Iseed\IseedServiceProvider.php (1910, 2023-03-27)
src\Orangehill\Iseed\stubs (0, 2023-03-27)
src\Orangehill\Iseed\stubs\seed.stub (352, 2023-03-27)
src\config (0, 2023-03-27)
src\config\config.php (129, 2023-03-27)
tests (0, 2023-03-27)
tests\IseedTest.php (76212, 2023-03-27)
tests\stubs (0, 2023-03-27)
tests\stubs\seed.stub (346, 2023-03-27)
tests\stubs\seed_5.stub (1017, 2023-03-27)
tests\stubs\seed_505.stub (68371, 2023-03-27)
tests\stubs\seed_blank.stub (300, 2023-03-27)

**Inverse seed generator (iSeed)** is a Laravel package that provides a method to generate a new seed file based on data from the existing database table. [![Build Status](https://travis-ci.org/orangehill/iseed.png)](http://travis-ci.org/orangehill/iseed) [![Latest Stable Version](https://poser.pugx.org/orangehill/iseed/v/stable.png)](https://packagist.org/packages/orangehill/iseed) [![Total Downloads](https://poser.pugx.org/orangehill/iseed/downloads.png)](https://packagist.org/packages/orangehill/iseed) [![Analytics](https://ga-beacon.appspot.com/UA-193***60-35/iseed?useReferrer&flat)](https://github.com/igrigorik/ga-beacon) ## Installation ### 1. Require with [Composer](https://getcomposer.org/) ```sh composer require orangehill/iseed ``` **Laravel 5.3.7 and below** or **Laravel 4** need specific version ```sh composer require orangehill/iseed:2.2 # Laravel 5.3.7 and below composer require orangehill/iseed:1.1 # Laravel 4 ``` ### 2. Add Service Provider (Laravel 5.4 and below) Latest Laravel versions have auto dicovery and automatically add service provider - if you're using 5.4.x and below, remember to add it to `providers` array at `/app/config/app.php`: ```php // ... Orangehill\Iseed\IseedServiceProvider::class, ``` ## Artisan command options ### [table_name] Mandatory parameter which defines which table/s will be used for seed creation. Use CSV notation for multiple tables. Seed file will be generated for each table. Examples: ``` php artisan iseed my_table ``` ``` php artisan iseed my_table,another_table ``` ### classnameprefix & classnamesuffix Optionally specify a prefix or suffix for the Seeder class name and file name. This is useful if you want to create an additional seed for a table that has an existing seed without overwriting the existing one. Examples: ``` php artisan iseed my_table --classnameprefix=Customized ``` outputs CustomizedMyTableSeeder.php ``` php artisan iseed my_table,another_table --classnameprefix=Customized ``` outputs CustomizedMyTableSeeder.php and CustomizedAnotherTableSeeder.php ``` php artisan iseed my_table --classnamesuffix=Customizations ``` outputs MyTableCustomizationsSeeder.php ``` php artisan iseed my_table,another_table --classnamesuffix=Customizations ``` outputs MyTableCustomizationsSeeder.php and AnotherTableCustomizationsSeeder.php ### force Optional parameter which is used to automatically overwrite any existing seeds for desired tables Example: The following command will overwrite `UsersTableSeeder.php` if it already exists in laravel's seeds directory. ``` php artisan iseed users --force ``` ### dumpauto Optional boolean parameter that controls the execution of `composer dump-autoload` command. Defaults to true. Example that will stop `composer dump-autoload` from execution: ``` php artisan iseed users --dumpauto=false ``` ### clean Optional parameter which will clean `app/database/seeds/DatabaseSeeder.php` before creating new seed class. Example: ``` php artisan iseed users --clean ``` ### database Optional parameter which specifies the DB connection name. Example: ``` php artisan iseed users --database=mysql2 ``` ### max Optional parameter which defines the maximum number of entries seeded from a specified table. In case of multiple tables, limit will be applied to all of them. Example: ``` php artisan iseed users --max=10 ``` ### chunksize Optional parameter which defines the size of data chunks for each insert query. Example: ``` php artisan iseed users --chunksize=100 ``` ### orderby Optional parameter which defines the column which will be used to order the results by, when used in conjunction with the max parameter that allows you to set the desired number of exported database entries. Example: ``` artisan iseed users --max=10 --orderby=id ``` ### direction Optional parameter which allows you to set the direction of the ordering of results; used in conjuction with orderby parameter. Example: ``` artisan iseed users --max=10 --orderby=id --direction=desc ``` ### exclude Optional parameter which accepts comma separated list of columns that you'd like to exclude from tables that are being exported. In case of multiple tables, exclusion will be applied to all of them. Example: ``` php artisan iseed users --exclude=id php artisan iseed users --exclude=id,created_at,updated_at ``` ### prerun Optional parameter which assigns a laravel event name to be fired before seeding takes place. If an event listener returns `false`, seed will fail automatically. You can assign multiple preruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of prerun event names. Example: The following command will make a seed file which will fire an event named 'someEvent' before seeding takes place. ``` php artisan iseed users --prerun=someEvent ``` The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed before seeding. ``` php artisan iseed users,groups --prerun=someUserEvent,someGroupEvent ``` The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed before seeding. Value for the users table prerun was omitted here, so `users` table seed will have no prerun event assigned. ``` php artisan iseed users,groups --prerun=,someGroupEvent ``` ### postrun Optional parameter which assigns a laravel event name to be fired after seeding takes place. If an event listener returns `false`, seed will be executed, but an exception will be thrown that the postrun failed. You can assign multiple postruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of postrun event names. Example: The following command will make a seed file which will fire an event named 'someEvent' after seeding was completed. ``` php artisan iseed users --postrun=someEvent ``` The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed after seeding. ``` php artisan iseed users,groups --postrun=someUserEvent,someGroupEvent ``` The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed after seeding. Value for the users table postrun was omitted here, so `users` table seed will have no postrun event assigned. ``` php artisan iseed users,groups --postrun=,someGroupEvent ``` ### noindex By using --noindex the seed can be generated as a non-indexed array. The use case for this feature is when you need to merge two seed files. Example: ``` php artisan iseed users --noindex ``` ## Usage To generate a seed file for your users table simply call: `\Iseed::generateSeed('users', 'connectionName', 'numOfRows');`. `connectionName` and `numOfRows` are not required arguments. This will create a file inside a `/database/seeds` (`/app/database/seeds` for Laravel 4), with the contents similar to following example: ```php truncate(); \DB::table('users')->insert(array ( 0 => array ( 'id' => '1', 'email' => 'admin@admin.com', 'password' => '$2y$10$tUGCkQf/0NY3w1l9sobGsudt6UngnoVXx/lUoh9ElcSOD0ERRkK9C', 'permissions' => NULL, 'activated' => '1', 'activation_code' => NULL, 'activated_at' => NULL, 'last_login' => NULL, 'persist_code' => NULL, 'reset_password_code' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'created_at' => '2013-06-11 07:47:40', 'updated_at' => '2013-06-11 07:47:40', ), 1 => array ( 'id' => '2', 'email' => 'user@user.com', 'password' => '$2y$10$ImNvsMzK/BOgNSYgpjs/3OjMKMHeA9BH/hjl43EiuBuLkZGPMuZ2W', 'permissions' => NULL, 'activated' => '1', 'activation_code' => NULL, 'activated_at' => NULL, 'last_login' => '2013-06-11 07:54:57', 'persist_code' => '$2y$10$C0la8WuyqC6AU2TpUwj0I.E3Mrva8A3tuVFWxXN5u7jswRKzsYYHK', 'reset_password_code' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'created_at' => '2013-06-11 07:47:40', 'updated_at' => '2013-06-11 07:54:57', ), )); } } ``` This command will also update `/database/seeds/DatabaseSeeder.php` (`/app/database/seeds/DatabaseSeeder.php` for Laravel 4) to include a call to this newly generated seed class. If you wish you can define custom iSeed template in which all the calls will be placed. You can do this by using `#iseed_start` and `#iseed_end` templates anywhere within `/database/seeds/DatabaseSeeder.php` (`/app/database/seeds/DatabaseSeeder.php` for Laravel 4), for example: ```php 500 // Maximum number of rows per insert statement

近期下载者

相关文件


收藏者