Download the PHP package ajcastro/fk-adder without Composer
On this page you can find all versions of the php package ajcastro/fk-adder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ajcastro/fk-adder
More information about ajcastro/fk-adder
Files in ajcastro/fk-adder
Package fk-adder
Short Description Lets you add foreign keys in a swift! Foreign key adder in laravel migration.
License MIT
Informations about the package fk-adder
FkAdder for Laravel Migration
Lets you add foreign keys smart and easy! Foreign key adder for laravel migration.
For Laravel 4.2
and 5.*
.
The purpose of FkAdder
is to simplify declaration of foreign key columns in migration.
Things that FkAdder
do for you:
- Remembers the data type of a foreign key, and it will provide the correct data type for you, so that you don't have to recall the data type of foreign key column whenever you need that particular foreign key.
- Lets you create migration tables in any order. This solves the problem when your table is created prior than the reference table. Usually this may cause error like
Reference table some_table does not exist
, this happens when referencing the table which are to be migrated on last part of migrations. - Speeds up laravel migration development.
Installation
composer require ajcastro/fk-adder
Alias
Add alias into config/app.php
file. You can skip this because of laravel's auto-discovery.
Configuration
Create a config file named config/fk_adder.php
Setup
There are two ways to setup your foreign keys: string-based declaration and class-based declaration. String-based is preferred for simpler datatype declaration.
String-based declaration
Open your fk_datatypes_path
file and add the foreign key declaration in the array.
The array keys are the foreign key columns and its values are the datatypes.
The reference tables are smartly guessed already by remove the _id
and pluralizing the foreign key names e.g. user_id
-> users
.
Since version 1.2, you can now also define the reference table. This is helpful for foreign keys which has custom table names.
Class-based declaration
Create classes of foreign keys declaration inside your fk_namespace
directory path.
Naming Convention
If the foreign key is e.g. user_id
, then the class name should be UserId
.
Example:
Sample Usage, Before vs After
Before
After
More Features, Benefits and Explanations
License
Released under MIT License.