deka / scopes
This package adds configuerable scoping to a laravel application based on the url through which it is loaded.
Requires
- php: ^8.0
- danielstjules/stringy: ~3.1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^9.3
- psalm/plugin-laravel: ^1.2
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2025-03-28 11:07:12 UTC
README
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.