deka/scopes

This package adds configuerable scoping to a laravel application based on the url through which it is loaded.

1.0 2022-07-28 04:51 UTC

This package is auto-updated.

Last update: 2024-04-28 09:22:12 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Through this package scopes can be configured for any url addressing the Laravel application. Through this mechanism the application can hold multiple sites and serve the right content based on the given scope.

Installation

You can install the package via composer:

composer require dirk-kokx/scopes

You can publish the config file with:

php artisan vendor:publish --provider="DekaWebdesign\Scopes\ScopesServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'driver' => 'config',
    'scopes' => [
        [
            'id' => 1,
            'url' => env('APP_URL', 'http://localhost'),
            'name' => 'Main Website',
            'locales' => [
                'nl' => 'nl_NL',
            ],
            'default_locale' => 'nl',
        ],
    ],
];

Usage

When addressing the app using a 'web' route, the locale is automatically set through the Middleware 'SetScope'. If there are multiple locales set it defaults to the default locale, or sets the one which key it finds as the first segment after the base url.

Scopes can be defined in the config or dynamically through the database. Please run 'php artisan migrate' to set the database table.

A Facade (Scopes) is available with the following methods:

    //returns the current Scope object
    Scopes::getCurrent();

    //returns the key of the currently set locale
    Scopes::getLocalePrefix();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@deka-webdesign.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.