├── LICENSE ├── README.md ├── composer.json └── src ├── Commands ├── JsonSeedsCreateCommand.php └── JsonSeedsOverwriteCommand.php ├── JsonDatabaseSeeder.php ├── JsonSeederServiceProvider.php ├── Utils ├── SeederResult.php └── SeederResultTable.php └── jsonseeder.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Timo Körber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Laravel JSON Seeder](https://user-images.githubusercontent.com/65356688/86782944-fe5aa180-c05f-11ea-9267-1581c7f991e1.jpg) 2 | 3 | ## Laravel JSON Seeder 4 | 5 | Create and use JSON files to seed your database in your Laravel applications. 6 | 7 | This package works both ways! 8 | 9 | - Export your database into JSON files 10 | - Use JSON files to seed your database 11 | 12 | ## Installation 13 | 14 | **Require this package** with composer. It is recommended to only require the package for development. 15 | 16 | ```shell 17 | composer require timokoerber/laravel-json-seeder --dev 18 | ``` 19 | 20 | Next you need to **publish** the config file and register the required commands with ... 21 | 22 | ```shell 23 | php artisan vendor:publish --provider="TimoKoerber\LaravelJsonSeeder\JsonSeederServiceProvider" 24 | ``` 25 | 26 | This will create the file `config/jsonseeder.php` where you can find the configurations. 27 | 28 | Next add the JsonSeederServiceProvider to the `providers` array in `config/app.php` ... 29 | 30 | ```php 31 | // config/app.php 32 | 33 | 'providers' => [ 34 | ... 35 | 36 | TimoKoerber\LaravelJsonSeeder\JsonSeederServiceProvider::class, 37 | 38 | ... 39 | ] 40 | ``` 41 | 42 | ## Creating JSON seeds from database 43 | ![Laravel JSON Seeder - Creating JSON seeds from database](https://user-images.githubusercontent.com/65356688/86143845-3ceadc00-baf5-11ea-956f-d707b88d148c.gif) 44 | 45 | Of course you can create the JSON files manually. But if you already have a good development database, you can easily export it into JSON seeds. 46 | 47 | You can create seeds for **every table in your database** by calling ... 48 | 49 | ```shell 50 | php artisan jsonseeds:create 51 | ``` 52 | This will create one JSON file for watch table in your database (i.e. table *users* -> *users.json*, table *posts* -> *posts.json*, etc.). 53 | 54 | If you only want to create a seed of **one specific table** (i.e. `users`), call ... 55 | 56 | ```shell 57 | php artisan jsonseeds:create users 58 | ``` 59 | 60 | Existing files **won't be overwritten** by default. If you call the command again, a **sub-directory will be created** and the JSON seeds will be stored there. 61 | If you want to **overwrite the existing seeds**, use the `overwrite` option like ... 62 | 63 | ```shell 64 | php artisan jsonseeds:create users -o|--overwrite 65 | ``` 66 | 67 | or just **use the command** ... 68 | 69 | ```shell 70 | php artisan jsonseeds:overwrite users 71 | ``` 72 | 73 | ## Seeding 74 | 75 | ![Laravel JSON Seeder - Seeding](https://user-images.githubusercontent.com/65356688/86143769-23e22b00-baf5-11ea-90e6-0631a41d81c4.gif) 76 | 77 | Go to your `databas/seeds/DatabaseSeeder.php` and add the JsonSeeder inside the `run()` method like this ... 78 | 79 | ```php 80 | // database/seeds/DatabaseSeeder.php 81 | 82 | class DatabaseSeeder extends Seeder 83 | { 84 | public function run() 85 | { 86 | $this->call(TimoKoerber\LaravelJsonSeeder\JsonDatabaseSeeder::class); 87 | } 88 | } 89 | ``` 90 | 91 | You can now call the JSON Seeder with the **usual Artisan command** ... 92 | 93 | ```shell 94 | php artisan db:seed 95 | ``` 96 | 97 | ## Settings & Configurations 98 | 99 | ### Directory 100 | 101 | By default your seeds will be written into or read from the directory `/database/json`. If you want a different directory, you can add the environment variable 102 | `JSON_SEEDS_DIRECTORY` in your `.env` file ... 103 | 104 | ``` 105 | # .env 106 | 107 | JSON_SEEDS_DIRECTORY=database/json 108 | ``` 109 | 110 | ### Ignoring tables 111 | 112 | Some tables in your database might not require any seeds. 113 | If you want to ignore these tables, you can put them into the setting `ignore-tables` in the `/config.jsonseeder.php` 114 | 115 | ```php 116 | // config/jsonseeder.php 117 | 118 | 'ignore-tables' => [ 119 | 'migrations', 120 | 'failed_jobs', 121 | 'password_resets', 122 | ] 123 | ``` 124 | 125 | If a table in your database is empty, the LaravelJsonSeeder will create a JSON file with an empty array by default. This might be useful if you want your seeds to truncate this table. 126 | If you don't want this, you can change the setting `ignore-empty-tables` in `config/jsonseeder.php`, so no JSON seed will be created. 127 | 128 | ```php 129 | // config/jsonseeder.php 130 | 131 | 'ignore-empty-tables' => true 132 | ``` 133 | 134 | > **Important!!!** Do not forget to clear the cache after editing the config file: `php artisan cache:clear` 135 | 136 | ### Environments 137 | 138 | The environment variable `JSON_SEEDS_DIRECTORY` might be useful if you are using seeds in Unit Tests and want to use different seeds for this. 139 | 140 | ``` 141 | - database 142 | - json 143 | - development 144 | - comapanies.json 145 | - users.json 146 | - posts.json 147 | - testing 148 | - users.json 149 | - posts.json 150 | ``` 151 | #### Development 152 | ``` 153 | # .env 154 | 155 | JSON_SEEDS_DIRECTORY=database/json/development 156 | ``` 157 | #### Testing 158 | ```xml 159 | // phpunit.xml 160 | 161 | 162 | 163 | 164 | 165 | 166 | ``` 167 | 168 | ## Errors & Warnings 169 | 170 | ![jsonseeder-errors](https://user-images.githubusercontent.com/65356688/86142165-2e9bc080-baf3-11ea-99b8-9bef46cd61f2.gif) 171 | 172 | 173 | | Error | Type | Solution | 174 | | ------| -----| -------- | 175 | | Table does not exist! | Error | The name of the JSON file does not match any table. Check the filename or create the table. | 176 | | JSON syntax is invalid! | Error | The JSON text inside the file seems to be invalid. Check if the JSON format is correct.| 177 | | Exception occured! Check logfile! | Error | There seems to be a problem with the Database. Check your system and your default logfile. | 178 | | JSON file is empty! | Error | The JSON file is completely empty, which makes it useless. If it should truncate the table, provide an empty array `[]`. Otherwise delelte it.| 179 | | JSON file has no rows! | Warning | The JSON file contains only an empty array `[]`. This results in a truncated table and might not be intended. | 180 | | Missing fields! | Warning | At least one row in the JSON file is missing a field, that is present in the database table. Check for typos or provide it in the JSON file. | 181 | | Unknown fields! | Warning | At least one row in the JSON file has a field that does not exist in the database. Check for typos or make sure to add it to the database table. | 182 | 183 | 184 | ## License 185 | 186 | Copyright © Timo Körber 187 | 188 | Laravel JSON Seeder is open-sourced software licensed under the [MIT license](LICENSE). 189 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "timokoerber/laravel-json-seeder", 3 | "type": "project", 4 | "description": "Create and use JSON files to seed your database in your Laravel applications", 5 | "keywords": [ 6 | "laravel", 7 | "seeds", 8 | "seeder", 9 | "database" 10 | ], 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Timo Körber", 15 | "email": "koerber.timo@gmail.com" 16 | } 17 | ], 18 | "require-dev": { 19 | "php": "^7.1.3", 20 | "ext-json": "*", 21 | "illuminate/console": "^5.6|^6|^7|^8", 22 | "illuminate/filesystem": "^5.6|^6|^7|^8", 23 | "illuminate/support": "^5.6|^6|^7|^8", 24 | "illuminate/database": "^5.6|^6|^7|^8" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "TimoKoerber\\LaravelJsonSeeder\\": "src/" 29 | } 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "providers": [ 34 | "TimoKoerber\\LaravelJsonSeeder\\JsonSeederServiceProvider" 35 | ] 36 | } 37 | }, 38 | "minimum-stability": "dev" 39 | } 40 | -------------------------------------------------------------------------------- /src/Commands/JsonSeedsCreateCommand.php: -------------------------------------------------------------------------------- 1 | seedsDirectory = config('jsonseeder.directory', '/database/json'); 36 | $this->tablesToIgnore = config('jsonseeder.ignore-tables', []); 37 | $this->ignoreEmptyTables = config('jsonseeder.ignore-empty-tables', false); 38 | } 39 | 40 | public function handle() 41 | { 42 | $this->tableName = $this->argument('table'); 43 | $this->overwriteExistingFiles = $this->option('overwrite'); 44 | 45 | $this->process(); 46 | } 47 | 48 | protected function process() 49 | { 50 | $this->line('Environment: '.env('APP_ENV')); 51 | $this->line('Overwrite existing files: '.($this->overwriteExistingFiles ? 'Yes' : 'No')); 52 | 53 | try { 54 | $this->createJsonFiles(); 55 | } catch (Exception $e) { 56 | $this->error($e->getMessage()); 57 | } 58 | } 59 | 60 | protected function createJsonFiles() 61 | { 62 | $tablesToExport = $this->getTablesToExport(); 63 | 64 | $seedsDirectory = $this->seedsDirectory.'/'; 65 | $basePath = base_path($this->seedsDirectory).'/'; 66 | 67 | $FileSystem = new Filesystem(); 68 | 69 | if (! $FileSystem->exists($basePath)) { 70 | File::makeDirectory($basePath, 0755, true); 71 | } 72 | 73 | if ($this->tableName) { 74 | $filename = $this->tableName.'.json'; 75 | $existingFiles = $FileSystem->exists($basePath.$filename); 76 | } else { 77 | $existingFiles = (bool) $FileSystem->files($basePath); 78 | } 79 | 80 | // create sub-directory so existing files won't be overwritten 81 | if ($existingFiles && ! $this->overwriteExistingFiles) { 82 | $directory = now()->toDateTimeString(); 83 | $basePath .= $directory.'/'; 84 | $seedsDirectory .= $directory.'/'; 85 | File::makeDirectory($basePath, 0755, true); 86 | } 87 | 88 | $this->line(''); 89 | 90 | foreach ($tablesToExport as $tableName) { 91 | $this->line('Create seeds for table '.$tableName); 92 | $content = DB::table($tableName)->select()->get(); 93 | $rowsCount = count($content); 94 | 95 | if ($this->ignoreEmptyTables && $rowsCount === 0) { 96 | $this->outputWarning('No JSON file was created, because table was empty.'); 97 | continue; 98 | } 99 | 100 | $filename = $tableName.'.json'; 101 | 102 | try { 103 | File::put($basePath.$filename, $content->toJson(JSON_PRETTY_PRINT)); 104 | $this->outputInfo('Created '.$seedsDirectory.$filename.' ('.$rowsCount.' rows)'); 105 | } catch (\Exception $e) { 106 | Log::alert($e->getMessage()); 107 | } 108 | } 109 | } 110 | 111 | protected function getTablesToExport() 112 | { 113 | if ($this->tableName) { 114 | if (! Schema::hasTable($this->tableName)) { 115 | throw new \Exception('Given table '.$this->tableName.' does not exist.'); 116 | } 117 | 118 | return [$this->tableName]; 119 | } 120 | 121 | $tables = $this->getDatabaseTables(); 122 | 123 | if ($this->tablesToIgnore) { 124 | $this->line('Ignore tables: '.implode(', ', $this->tablesToIgnore)); 125 | $tables = array_diff($tables, $this->tablesToIgnore); 126 | } 127 | 128 | if (! $tables) { 129 | throw new \Exception('No Database tables found.'); 130 | } 131 | 132 | return $tables; 133 | } 134 | 135 | protected function getDatabaseTables() 136 | { 137 | switch (config('database.default')) { 138 | case 'sqlite': 139 | $tables = $this->getSqliteTables(); 140 | break; 141 | case 'mysql': 142 | $tables = $this->getMysqlTables(); 143 | break; 144 | case 'pgsql': 145 | $tables = $this->getPostgrsqlTables(); 146 | break; 147 | default: 148 | throw new Exception('Database connection "'.config('database.default').'" is not supported!'); 149 | } 150 | 151 | return array_map(static function ($element) { 152 | $array = (array) $element; 153 | 154 | return array_pop($array); 155 | }, $tables); 156 | } 157 | 158 | protected function getMysqlTables() 159 | { 160 | return DB::select('SHOW TABLES'); 161 | } 162 | 163 | protected function getSqliteTables() 164 | { 165 | return DB::select("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"); 166 | } 167 | 168 | private function getPostgrsqlTables() 169 | { 170 | return DB::select("SELECT table_name FROM information_schema.tables WHERE table_schema='public'"); 171 | } 172 | 173 | protected function outputInfo(string $message) 174 | { 175 | $this->info(' > '.$message); 176 | } 177 | 178 | protected function outputWarning(string $message) 179 | { 180 | $this->warn(' > '.$message); 181 | } 182 | 183 | protected function outputError(string $message) 184 | { 185 | $this->error(' > '.$message); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/Commands/JsonSeedsOverwriteCommand.php: -------------------------------------------------------------------------------- 1 | tableName = $this->argument('table'); 15 | $this->overwriteExistingFiles = true; 16 | 17 | $this->process(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/JsonDatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | command->line('Environment: '.$env); 29 | 30 | $seedsDirectory = config('jsonseeder.directory', '/database/json'); 31 | $absoluteSeedsDirectory = base_path($seedsDirectory); 32 | 33 | if (! File::isDirectory($absoluteSeedsDirectory)) { 34 | $this->command->error('The directory '.$seedsDirectory.' was not found.'); 35 | 36 | return false; 37 | } 38 | 39 | $this->command->line('Directory: '.$seedsDirectory); 40 | 41 | $jsonFiles = $this->getJsonFiles($absoluteSeedsDirectory); 42 | 43 | if (! $jsonFiles) { 44 | $this->command->warn('The directory '.$seedsDirectory.' has no JSON seeds.'); 45 | $this->command->line('You can create seeds from you database by calling php artisan jsonseeds:create'); 46 | 47 | return false; 48 | } 49 | 50 | $this->command->line('Found '.count($jsonFiles).' JSON files in '.$seedsDirectory.''); 51 | $this->SeederResultTable = new SeederResultTable(); 52 | 53 | $this->seed($jsonFiles); 54 | 55 | return true; 56 | } 57 | 58 | public function seed(array $jsonFiles) 59 | { 60 | Schema::disableForeignKeyConstraints(); 61 | 62 | foreach ($jsonFiles as $jsonFile) { 63 | $SeederResult = new SeederResult(); 64 | $this->SeederResultTable->addRow($SeederResult); 65 | 66 | $filename = $jsonFile->getFilename(); 67 | $tableName = Str::before($filename, '.json'); 68 | $SeederResult->setFilename($filename); 69 | $SeederResult->setTable($tableName); 70 | 71 | $this->command->line('Seeding '.$filename); 72 | 73 | if (! Schema::hasTable($tableName)) { 74 | $this->outputError(SeederResult::ERROR_NO_TABLE); 75 | 76 | $SeederResult->setStatusAborted(); 77 | $SeederResult->setError(SeederResult::ERROR_NO_TABLE); 78 | $SeederResult->setTableStatus(SeederResult::TABLE_STATUS_NOT_FOUND); 79 | 80 | continue; 81 | } 82 | 83 | $SeederResult->setTableStatus(SeederResult::TABLE_STATUS_EXISTS); 84 | 85 | $filepath = $jsonFile->getRealPath(); 86 | $content = File::get($filepath); 87 | $jsonArray = $this->getValidJsonString($content, $SeederResult); 88 | 89 | // empty array is a valid result, check for null 90 | if ($jsonArray === null) { 91 | continue; 92 | } 93 | 94 | DB::table($tableName)->truncate(); 95 | 96 | if (empty($jsonArray)) { 97 | $this->outputWarning(SeederResult::ERROR_NO_ROWS); 98 | $SeederResult->setError(SeederResult::ERROR_NO_ROWS); 99 | 100 | continue; 101 | } 102 | 103 | $tableColumns = DB::getSchemaBuilder()->getColumnListing($tableName); 104 | 105 | foreach ($jsonArray as $data) { 106 | $this->compareJsonWithTableColumns($data, $tableColumns, $SeederResult); 107 | $data = Arr::only($data, $tableColumns); 108 | 109 | try { 110 | DB::table($tableName)->insert($data); 111 | $SeederResult->addRow(); 112 | $SeederResult->setStatusSucceeded(); 113 | } catch (\Exception $e) { 114 | $this->outputError(SeederResult::ERROR_EXCEPTION); 115 | $SeederResult->setError(SeederResult::ERROR_EXCEPTION); 116 | $SeederResult->setStatusAborted(); 117 | Log::warning($e->getMessage()); 118 | break; 119 | } 120 | } 121 | 122 | $this->outputInfo('Seeding successful!'); 123 | } 124 | 125 | Schema::enableForeignKeyConstraints(); 126 | 127 | $this->command->line(''); 128 | $this->command->table($this->SeederResultTable->getHeader(), $this->SeederResultTable->getResult()); 129 | } 130 | 131 | protected function getJsonFiles($seedsDirectory) 132 | { 133 | $files = File::files($seedsDirectory); 134 | 135 | $files = array_filter($files, static function ($filename) { 136 | return Str::endsWith($filename, 'json'); 137 | }); 138 | 139 | return array_values($files); 140 | } 141 | 142 | protected function compareJsonWithTableColumns(array $item, array $columns, SeederResult $SeederResult) 143 | { 144 | $diff = array_diff($columns, array_keys($item)); 145 | 146 | if ($diff) { 147 | $SeederResult->setError(SeederResult::ERROR_FIELDS_MISSING.' '.implode(',', $diff)); 148 | } 149 | 150 | $diff = array_diff(array_keys($item), $columns); 151 | 152 | if ($diff) { 153 | $SeederResult->setError(SeederResult::ERROR_FIELDS_UNKNOWN.' '.implode(',', $diff)); 154 | } 155 | } 156 | 157 | protected function getValidJsonString($content, SeederResult $SeederResult) 158 | { 159 | if (empty($content)) { 160 | $this->outputError(SeederResult::ERROR_FILE_EMPTY); 161 | $SeederResult->setError(SeederResult::ERROR_FILE_EMPTY); 162 | $SeederResult->setStatusAborted(); 163 | 164 | return null; 165 | } 166 | 167 | $jsonContent = json_decode($content, true); 168 | 169 | if (json_last_error()) { 170 | $this->outputError(SeederResult::ERROR_SYNTAX_INVALID); 171 | $SeederResult->setError(SeederResult::ERROR_SYNTAX_INVALID); 172 | $SeederResult->setStatusAborted(); 173 | 174 | return null; 175 | } 176 | 177 | $SeederResult->setStatusSucceeded(); 178 | 179 | return $jsonContent; 180 | } 181 | 182 | protected function outputInfo(string $message) 183 | { 184 | $this->command->info(' > '.$message); 185 | } 186 | 187 | protected function outputWarning(string $message) 188 | { 189 | $this->command->warn(' > '.$message); 190 | } 191 | 192 | protected function outputError(string $message) 193 | { 194 | $this->command->error(' > '.$message); 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/JsonSeederServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 14 | __DIR__.'/jsonseeder.php' => config_path('jsonseeder.php'), 15 | ]); 16 | 17 | if ($this->app->runningInConsole()) { 18 | $this->commands(JsonSeedsCreateCommand::class); 19 | $this->commands(JsonSeedsOverwriteCommand::class); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Utils/SeederResult.php: -------------------------------------------------------------------------------- 1 | filename = $filename; 38 | 39 | return $this; 40 | } 41 | 42 | public function getFilename() 43 | { 44 | return $this->filename; 45 | } 46 | 47 | public function getRows() 48 | { 49 | if (! $this->rows) { 50 | return '-'; 51 | } 52 | 53 | return $this->rows; 54 | } 55 | 56 | public function setRows($rows) 57 | { 58 | $this->rows = $rows; 59 | } 60 | 61 | public function addRow() 62 | { 63 | $this->rows++; 64 | } 65 | 66 | public function getTable() 67 | { 68 | return $this->table; 69 | } 70 | 71 | public function getTableMessage() 72 | { 73 | if ($this->tableStatus === self::TABLE_STATUS_EXISTS) { 74 | return ''.$this->getTable().''; 75 | } 76 | 77 | return ''.$this->getTable().''; 78 | } 79 | 80 | public function setTable($table) 81 | { 82 | $this->table = $table; 83 | } 84 | 85 | public function getResult() 86 | { 87 | return $this->result; 88 | } 89 | 90 | public function getResultMessage() 91 | { 92 | return ''.$this->result.''; 93 | } 94 | 95 | public function setResult($result) 96 | { 97 | $this->result = $result; 98 | } 99 | 100 | public function getError() 101 | { 102 | return $this->error; 103 | } 104 | 105 | public function getErrorMessage() 106 | { 107 | if ($this->status === self::STATUS_ABORTED) { 108 | return ''.$this->error.''; 109 | } 110 | 111 | return ''.$this->error.''; 112 | } 113 | 114 | public function setError($error) 115 | { 116 | $this->error = $error; 117 | } 118 | 119 | public function getStatus() 120 | { 121 | return $this->status; 122 | } 123 | 124 | public function getStatusMessage() 125 | { 126 | if ($this->status === self::STATUS_ABORTED) { 127 | return ''.$this->status.''; 128 | } 129 | 130 | return ''.$this->status.''; 131 | } 132 | 133 | public function setStatus($status) 134 | { 135 | $this->status = $status; 136 | } 137 | 138 | public function setStatusAborted() 139 | { 140 | $this->status = self::STATUS_ABORTED; 141 | } 142 | 143 | public function setStatusSucceeded() 144 | { 145 | $this->status = self::STATUS_SUCCEEDED; 146 | } 147 | 148 | public function getTableStatus() 149 | { 150 | return $this->tableStatus; 151 | } 152 | 153 | public function setTableStatus($tableStatus) 154 | { 155 | $this->tableStatus = $tableStatus; 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/Utils/SeederResultTable.php: -------------------------------------------------------------------------------- 1 | rows[] = $row; 15 | 16 | return $this; 17 | } 18 | 19 | public function getHeader() 20 | { 21 | return ['File', 'Table', 'Rows', 'Status', 'Message']; 22 | } 23 | 24 | public function getResult() 25 | { 26 | $result = []; 27 | foreach ($this->rows as $row) { 28 | $element = []; 29 | $element[] = $row->getFilename(); 30 | $element[] = $row->getTableMessage(); 31 | $element[] = $row->getRows(); 32 | $element[] = $row->getStatusMessage(); 33 | $element[] = $row->getResultMessage().$row->getErrorMessage(); 34 | $result[] = $element; 35 | } 36 | 37 | return $result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/jsonseeder.php: -------------------------------------------------------------------------------- 1 | env('JSON_SEEDS_DIRECTORY', 'database/json'), 8 | 9 | /* 10 | * Ignore these tables when creating seeds 11 | */ 12 | 'ignore-tables' => [ 13 | 'migrations', 14 | 'failed_jobs', 15 | 'password_resets', 16 | ], 17 | 18 | /* 19 | * Do not create a seed when the table is empty 20 | */ 21 | 'ignore-empty-tables' => false, 22 | ]; 23 | --------------------------------------------------------------------------------