acacha / periods by acacha

Laravel 5 package to add suport for historical data using multiple databases
390
1
3
Package Data
Maintainer Username: acacha
Maintainer Contact: sergiturbadenas@gmail.com (Sergi Tur Badenas)
Package Create Date: 2016-11-11
Package Last Update: 2016-11-11
Language: PHP
License: MIT
Last Refreshed: 2024-04-23 03:12:30
Package Statistics
Total Downloads: 390
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

periods

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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.