Skip to content

Database

Zane Hooper edited this page Feb 11, 2017 · 12 revisions

All packages have full access to modifying the database schema via Laravel migrations. It is recommended, though not required, to prefix all table names with pkg_<your package name>_, e.g. pkg_abuse_.

To create a migration, create a class in the package's database/migrations directory and make it extend App\Support\Database\Migration. The Migration class provides handy methods for interacting with the SynergyCP application, for instance adding Setting Groups and Settings:

Once you have completed the migration code, you can run this command from the main application:

php artisan migrate --path=packages/$PACKAGE/database/migrations

and php artisan migrate:rollback to roll back the migration.

Settings

The App\Support\Database\Migration class has helpful methods for adding Settings and Setting Groups:

    /**
     * @param string $name
     * @param array  $info
     *
     * @return SettingGroup
     */
    protected function addSettingGroup($name, array $info = []);

    /**
     * @param SettingGroup $group
     * @param string       $type
     * @param string       $name
     * @param array        $info
     *
     * @return Setting
     */
    protected function addSetting(SettingGroup $group, $type, $name, array $info = []);