acacha / periods
Laravel 5 package to add suport for historical data using multiple databases
Requires
- php: ~5.6|~7.0
Requires (Dev)
- phpunit/phpunit: ~4.0||~5.0
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-11-13 04:13:36 UTC
README
Laravel 5 packages to support multiple database connections for historical data (One period -> One database connection)
Install
Via Composer
$ composer require acacha/periods
Add PeriodsServiceProvider service provider to config/app.php file:
... /* * Package Service Providers... */ Acacha\Periods\Providers\PeriodsServiceProvider::class, ...
Publish files with:
php artisan vendor:publish --tag=acacha_periods
Usage
Register Laravel Middleware on class App\Http\Kernel.php at the end of web middleware group:
... protected $middlewareGroups = [ 'web' => [ ... \Acacha\Periods\Middleware\Periods::class ], ...
Customize your config. First adapt to your needs fil config/periods.php:
<?php return [ /* |-------------------------------------------------------------------------- | Session variable name for periods |-------------------------------------------------------------------------- | | This value is the name of the session vairable that storages desired period. */ 'session_variable' => 'ACACHA_PERIOD', /* |-------------------------------------------------------------------------- | Valid period values and related database connections |-------------------------------------------------------------------------- | | This value is an array that stores valid period values and his related | database connections. */ 'periods' => [ '2016-17' => env('DB_CONNECTION', 'mysql'), '2015-16' => env('DB_CONNECTION', 'mysql') . '_1516', '2014-15' => env('DB_CONNECTION', 'mysql') . '_1415', ], ];
By sure that you have multiple database connections (default sqlite, sqlite_1516, sqlite_1415...) at config file config/database.php:
... 'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), 'prefix' => '', ], 'sqlite_1516' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database1516.sqlite')), 'prefix' => '', ], 'sqlite_1415' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database1415.sqlite')), 'prefix' => '', ], ...
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email sergiturbadenas@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.