ktourvas / laravel-extensions
collection of laravel based functionality extending classes
Installs: 29
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
This package is not auto-updated.
Last update: 2024-09-21 09:17:23 UTC
README
Simple addon functionality classes for laravel.
Installation
require package in your laravel installation with
composer require ktourvas/laravel-extensions
after installation the package will automatically be discovered through laravel's auto-discovery feature.
follow the above with
php artisan vendor:publish
in order for the package's configuration file to be published.
Usage
Middleware
I like to register extra middleware through the ServiceProviders of project packages and not globally and that is because I usually work with different packages in one local installation that require different functionality each and I usually don't want them to interfere with eachother. So in that case a middleware would be registered through the register() method of a Service Provider like below
public function register() { $this->app['router']->aliasMiddleware('IpRestrict', Laravel\extensions\Http\Middleware\ipRestrict::class); }
ipRestrict
the ip restriction middleware checks a request's ip address against an array of whitelisted addresses set through configuration. The array is populated from the .env variable LE_WHITELIST. Values are separated with commas.
ex.
LE_WHITELIST=99.99.99.99,88.88.88.88,77.77.77.77
in the event of a non whitelisted address the request is aborted with a 404 response.
setLocale
the set locale middleware will check for the first segment on every request's url. If the first segment corresponds to a locale set through configuration, the application locale is set to that. Again in this case locale's are set through the .env variable LE_LOCALES
ex.
LE_LOCALES=en;el