2017 © Pedro Peláez
 

library dbchanger

Change your database with request headers.

image

mintellity/dbchanger

Change your database with request headers.

  • Monday, August 22, 2016
  • by mintellity
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

dbchanger

Change your database with request header. Laravel 5., (*1)

Installation

Require package in your composer.json:, (*2)

"mintellity/dbchanger" : "dev-master"

Publish config file:, (*3)

php artisan vendor:publish --provider="Mintellity\DbChanger\DbChangerServiceProvider"

Make sure the right user is set in the dbchanger.php config file. Your config should look like this:, (*4)

<?php

return [
    // this are the environments where dbchanger should work on. The active environment is fetched by .env file.
    'envs' => [
        'local'
    ],
    // this is the header parameter's name
    'headerParameter' => 'ApiTestIdentifier',
    // some infos about your db connection. Make sure this user is allowed to create databases.
    'connection' => [
        'host' => env('DB_HOST_TEST', 'localhost'),
        'user' => env('DB_USERNAME_TEST', 'homestead'),
        'password' => env('DB_PASSWORD_TEST', 'secret'),
        'prefix' => 'yourDbPrefix_'
    ]
];

Register the route-middleware in Kernel.php:, (*5)

$routeMiddleware = [
  'db.changeable' => \Mintellity\DbChanger\DbChangerMiddleware::class,
  ...
]

How to use it

Now you are ready to use the DbChanger package. All you need to do is adding a middleware to the routes, where you want to listen for the db-change header-parameter. For example do this:, (*6)

Route::group(['as' => 'api.', 'prefix' => 'api', 'namespace' => 'Api', 'middleware' => ['db.changeable']], function () {
// ...
});

If you send a request to one of this routes, you can add a header-parameter with the desired database to work on., (*7)

If you want to create a new database you have to add this route:, (*8)

Route::get('buildDatabase/{databaseName}/{forceCreate?}', [
        'as' => 'apitest.buildDatabase',
        'uses' => '\Mintellity\DbChanger\DbChangerController@buildDatabase'
    ]);

So if you run http://yourpage.app/buildDatabase/testdatabase1/true in your browser, the system will create a new database called testdatabase1 (prefix can be defined in the config file). Validation for your database name is required|alpha_num|max:30|min:1. If you create a new database or you force create it, your seeds will be fired automatically., (*9)

The Versions

22/08 2016

dev-master

9999999-dev

Change your database with request headers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Mintellity GmbH

mintellity

22/08 2016

0.1.1

0.1.1.0

Change your database with request headers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Mintellity GmbH

mintellity

22/08 2016

0.1.0

0.1.0.0

Change your database with request headers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Mintellity GmbH

mintellity