Download the PHP package illuminatech/enum-seeder without Composer

On this page you can find all versions of the php package illuminatech/enum-seeder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package enum-seeder

Laravel Enum Seeder


This extension allows easy creation of DB seeders for the dictionary (enum) type tables, such as statuses, types, categories and so on.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the "require" section of your composer.json.

Usage

Almost every project requires specification of so called 'dictionary' or 'enum' entities, such as statuses, types, categories and so on. It is not always practical to keep such data as PHP enums or class-base enums. Sometimes it has to be put into a database table. For example: when we need to provide ability for the system administrator to edit human-readable title or description of the particular category or status, or enable/disable particular records, or simply to keep the database integrity.

Obviously keeping dictionary (enum) in the database tables creates a problem of its synchronization. As our project evolves new categories and statuses may appear, and some may become obsolete. Thus, we need a tool, which allows updating of the data in the dictionary (enum) tables. This package provides such a tool.

The idea is in creation of the special kind of database seeder, which synchronizes particular enum table with the predefined data in the way, it could be invoked multiple times without creation of redundant records or breaking an integrity. You can create such seeder extending Illuminatech\EnumSeeder\EnumSeeder. For example:

With seeders defined in such way, you can invoke following command after each project update:

As the result table 'item_categories' will always be up-to-date with the values from ItemCategorySeeder::rows(). In case you need to add a new item category, you can simply add another entry to the ItemCategorySeeder::rows() and run the seeder again. It will gracefully add the missing records, keeping already existing ones intact.

You can control the seeding options overriding methods from Illuminatech\EnumSeeder\ControlsWorkflow.

Heads up! Make sure you do not setup a sequence (autoincrement) for the primary key (id) of the dictionary (enum) table, otherwise EnumSeeder may be unable to properly handle its data synchronization.

The example of the database migration for the dictionary (enum) table:

Tip: Remember that it is not mandatory for primary key field to be always an integer - you may use strings for it just as well, keeping your database records more human-readable. For example:

Processing of the obsolete records

By default Illuminatech\EnumSeeder\EnumSeeder does not deletes the records, which are no longer specified at rows() method, as the database may already contain the references to those records via foreign keys, and deleting enum value may cause a data loss. However, if you sure what you are doing, you can control the deletion feature via shouldDeleteObsolete() method. For example:

Each time ContentPageSeeder will be called, it will delete all the records from 'content_pages', which 'id' is missing at rows() method declaration.

Note: Remember that you can specify a complex logic at shouldDeleteObsolete() to suite your needs. For example, you can allow deleting of obsolete rows for "local" environment, while forbidding it for "prod":

Deletion is not the only way to deal with obsolete records. In order to keep the database integrity, it is better to simply mark the obsolete records as outdated, e.g. perform a "soft-delete". This can be achieved via shouldUpdateObsoleteWith() method. For example:

Common data for the records creation

You may simplify rows() method for the particular seeder extracting common attributes in shouldCreateWith() method. It defines the default attribute values for each created record, unless it explicitly overridden by the entry from rows(). For example:

Updating of the existing records

Each time the enum seeder is executed it updates existing records with the actual data from rows() if they mismatch. You can disable the update defining shouldUpdateExisting() method. For example:

However, most likely you will need to allow updating for some attributes, while disallow it for the others. For example, if you setup content pages, you probably want control whether particular page is active or not via seeder, while the content fields, which are edited by the administrator, should remain intact. This can be achieved using shouldUpdateExistingOnly() method. For example:

You may specify the attributes, which should be applied on each row update, using shouldUpdateExistingWith(). For example:

Heads up! Methods shouldUpdateExistingOnly() and shouldUpdateExistingWith() take precedence over shouldUpdateExisting(). If, at least, one of them defined, return value of shouldUpdateExisting() will be ignored, and the records will be updated anyway.

Eloquent enum seeders

It might be more convenient for you to operate Eloquent models instead of plain tables for enum seeding. Manipulating data via active record models allows you to use its full features such as "events", "timestamps" and "soft-delete". You can setup a enum seeder for particular Eloquent model using Illuminatech\EnumSeeder\EloquentEnumSeeder. For example:

Heads up! Remember to disable Illuminate\Database\Eloquent\Model::$incrementing for the enum Eloquent model, otherwise EloquentEnumSeeder may be unable to properly handle its data synchronization. For example:

Heads up! In case you are using string values as a primary key for enum table, you should also adjust Illuminate\Database\Eloquent\Model::$keyType accordingly. For example:


All versions of enum-seeder with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package illuminatech/enum-seeder contains the following files

Loading the files please wait ....