Download the PHP package davidvandertuijn/laravel-after-seeders without Composer
On this page you can find all versions of the php package davidvandertuijn/laravel-after-seeders. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download davidvandertuijn/laravel-after-seeders
More information about davidvandertuijn/laravel-after-seeders
Files in davidvandertuijn/laravel-after-seeders
Package laravel-after-seeders
Short Description Laravel After Seeders
License MIT
Informations about the package laravel-after-seeders
Laravel After Seeders
This library adds seeder functionality with versioning support for Laravel, making it ideal for a production environment. Seeders are stored in the database/after_seeders directory in JSON format. The execution progress of each seeder is tracked in the after_seeders table, ensuring that each seeder is only seed once.
Install
Install the package via Composer:
Run the migrations:
Publish the configuration file:
Usage
Create a New Seeder Automatically
Use the command below to create a complete seeder based on existing records in a database table.
The command will prompt you to include or exclude specific columns from the table. If you skip a column, it won’t be included in the seeder file. You can also define a range of record IDs to include.
Example prompt:
After completion, you’ll get the following message:
And the seeder will look like this:
Create a New Seeder Manually
Use the following command to create an empty “after seeder” file. This option is ideal if you’re already familiar with the JSON structure and prefer to manually input the data.
You’ll see the following output upon success:
A basic structure for the JSON file will look like this:
If you use Navicat for MySQL, it follows the same format when exporting data to a .json file.
Running Seeders
To execute pending “after seeders,” run the following command:
The command checks whether the specified table and columns exist. If not, the seeder will be skipped.
After completion, you’ll get the following message:
Handling created_at
If the table has a created_at column and it’s missing from the seeder, the current timestamp will be automatically inserted.
Update Or Insert
If the seeder contains an id column, the updateOrInsert method will be used. Otherwise, the insert method will be applied.
Tags
You can use tags to organize and manage your seeders more effectively. By adding a tag, you can group seeders and seed specific groups when needed.
Create a Seeder with a Tag
To generate a seeder based on existing records and assign a tag, use the --tag option:
Similarly, you can create an empty seeder and assign a tag:
Running Seeders by Tag
When running seeders, you can specify a tag to seed only the seeders that belong to that group:
This allows you to selectively execute seeders based on tags, making it easier to control which seeders are applied in different environments or scenarios.
Deployment
When deploying your application, you can execute seeders with specific tags using the deployment command. Before doing this, you’ll need to define the tags in your project’s configuration file located at config/after_seeders.php.
To run the seeders during deployment, simply use the following command:
All versions of laravel-after-seeders with dependencies
php Version >=8.0.0