├── LICENSE.md ├── README.md ├── composer.json └── src ├── FunServiceProvider.php └── Http └── FunController.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Miguel Piedrafita 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Fun :sparkles: 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/m1guelpf/laravel-fun.svg?style=flat-square)](https://packagist.org/packages/m1guelpf/laravel-fun) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/m1guelpf/laravel-fun.svg?style=flat-square)](https://packagist.org/packages/m1guelpf/laravel-fun) 5 | 6 | A fun package that registers a few routes bots usually search for, and gives them a nice surprise instead. Inspired by [this tweet](https://twitter.com/LiamHammett/status/1260984553570570240). 7 | 8 | ## Installation 9 | 10 | You can install the package via composer: 11 | 12 | ```bash 13 | composer require m1guelpf/laravel-fun 14 | ``` 15 | 16 | ## Usage 17 | 18 | Just enjoy! 19 | 20 | ## Contributing 21 | 22 | You can add more paths or redirects by editing the `FunServiceProvider` file! 23 | 24 | ## Credits 25 | 26 | - [Miguel Piedrafita](https://twitter.com/m1guelpf) 27 | - [Lian Hammett](https://twitter.com/LiamHammett) 28 | - [All Contributors](../../contributors) 29 | 30 | ## License 31 | 32 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 33 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "m1guelpf/laravel-fun", 3 | "description": ":package_description", 4 | "keywords": [ 5 | "m1guelpf", 6 | "laravel-fun", 7 | "laravel" 8 | ], 9 | "homepage": "https://github.com/m1guelpf/laravel-fun", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Miguel Piedrafita", 14 | "email": "soy@miguelpiedrafita.com", 15 | "homepage": "https://miguelpiedrafita.com", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "illuminate/http": "8.*", 21 | "illuminate/routing": "8.*", 22 | "illuminate/support": "8.*" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "M1guelpf\\Fun\\": "src" 27 | } 28 | }, 29 | "config": { 30 | "sort-packages": true 31 | }, 32 | "extra": { 33 | "laravel": { 34 | "providers": [ 35 | "M1guelpf\\Fun\\FunServiceProvider" 36 | ] 37 | } 38 | }, 39 | "minimum-stability": "dev", 40 | "prefer-stable": true 41 | } 42 | -------------------------------------------------------------------------------- /src/FunServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->routesAreCached()) { 60 | $this->registerRoutes(); 61 | } 62 | } 63 | 64 | protected function registerRoutes() 65 | { 66 | $routes = Router::getRoutes()->get('GET'); 67 | 68 | collect(static::PATHS) 69 | ->reject(fn ($path) => $this->routeExists($routes, $path)) 70 | ->each(fn ($path) => Router::get($path, FunController::class)); 71 | } 72 | 73 | protected function routeExists(array $routes, string $path) 74 | { 75 | [$fallbacks, $routes] = collect($routes)->partition(function ($route) { 76 | return $route->isFallback; 77 | }); 78 | 79 | return $routes->merge($fallbacks)->first(function (Route $route) use ($path) { 80 | $compiled = $route->compiled ?? $route->toSymfonyRoute()->compile(); 81 | 82 | return preg_match($compiled->getRegex(), rawurldecode($path)); 83 | }); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Http/FunController.php: -------------------------------------------------------------------------------- 1 | random()); 13 | } 14 | } 15 | --------------------------------------------------------------------------------