If your application has a fallback route like Route::get({slug})
, call to non-existent assets are processed by Laravel - causing strain on your server. If a lot of assets are not presenent (like on a staging server) this can even bring your application to a grinding halt.
This package contains middleware that aborts the request if it contains certain extensions, that you set in your .env file.
Step 1: Install the package via composer:
composer require accentinteractive/laravel-ignore-extensions
Step 2: Make sure to register the Middleware.
To use it on all requests, add it as the first option to the web
section under $middlewareGroups
in file app/Http/Kernel.php.
protected $middlewareGroups = [
'web' => [
\Accentinteractive\LaravelIgnoreExtensions\Http\Middleware\DoNotProcessExtensions::class,
],
];
To use it on specific requests, add it to any group or to the protected $middleware
property in file app/Http/Kernel.php.
protected $middleware = [
\Accentinteractive\LaravelIgnoreExtensions\Http\Middleware\DoNotProcessExtensions::class,
];
Step 3: Optionally publish the config file with:
php artisan vendor:publish --provider="Accentinteractive\LaravelIgnoreExtensions\LaravelIgnoreExtensionsServiceProvider" --tag="config"
Config for this package is stored in config('laravel-ignore-extensions')
The package uses auto discover. The package uses a middleware class that does the checking and aborting.
You can set the extensions to check for in the published config file, or by setting this values in .env. It defaults to 'jpg|gif|png|jpeg|txt|html|pdf|css|js'
EXTENSIONS_NOT_TO_PROCESS=jpg|gif|png|jpeg|txt|html|pdf|css|js
vendor/bin/phpunit tests
XDEBUG_MODE=coverage vendor/bin/phpunit tests --coverage-html code-coverage
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.