From 67b0511d6f5d71aab9906a04352cc9bbef90d040 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:04 +0000 Subject: [PATCH 01/12] Shift core files --- public/index.php | 49 ++++++++++++++------------------ resources/lang/en/validation.php | 1 + 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/public/index.php b/public/index.php index 4584cbc..a8137b1 100644 --- a/public/index.php +++ b/public/index.php @@ -1,60 +1,55 @@ - */ +use Illuminate\Contracts\Http\Kernel; +use Illuminate\Http\Request; define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- -| Register The Auto Loader +| Check If Application Is Under Maintenance |-------------------------------------------------------------------------- | -| Composer provides a convenient, automatically generated class loader for -| our application. We just need to utilize it! We'll simply require it -| into the script here so that we don't have to worry about manual -| loading any of our classes later on. It feels great to relax. +| If the application is maintenance / demo mode via the "down" command we +| will require this file so that any prerendered template can be shown +| instead of starting the framework, which could cause an exception. | */ -require __DIR__.'/../vendor/autoload.php'; +if (file_exists(__DIR__.'/../storage/framework/maintenance.php')) { + require __DIR__.'/../storage/framework/maintenance.php'; +} /* |-------------------------------------------------------------------------- -| Turn On The Lights +| Register The Auto Loader |-------------------------------------------------------------------------- | -| We need to illuminate PHP development, so let us turn on the lights. -| This bootstraps the framework and gets it ready for use, then it -| will load up this application so that we can run it and send -| the responses back to the browser and delight our users. +| Composer provides a convenient, automatically generated class loader for +| this application. We just need to utilize it! We'll simply require it +| into the script here so we don't need to manually load our classes. | */ -$app = require_once __DIR__.'/../bootstrap/app.php'; +require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | -| Once we have the application, we can handle the incoming request -| through the kernel, and send the associated response back to -| the client's browser allowing them to enjoy the creative -| and wonderful application we have prepared for them. +| Once we have the application, we can handle the incoming request using +| the application's HTTP kernel. Then, we will send the response back +| to this client's browser, allowing them to enjoy our application. | */ -$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); +$app = require_once __DIR__.'/../bootstrap/app.php'; -$response = $kernel->handle( - $request = Illuminate\Http\Request::capture() -); +$kernel = $app->make(Kernel::class); -$response->send(); +$response = tap($kernel->handle( + $request = Request::capture() +))->send(); $kernel->terminate($request, $response); diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index a65914f..2e2820b 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -90,6 +90,7 @@ 'string' => 'The :attribute must be at least :min characters.', 'array' => 'The :attribute must have at least :min items.', ], + 'multiple_of' => 'The :attribute must be a multiple of :value', 'not_in' => 'The selected :attribute is invalid.', 'not_regex' => 'The :attribute format is invalid.', 'numeric' => 'The :attribute must be a number.', From 780df3121697fc37bbb4297d5c00db36f1bc3532 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 02/12] Shift exception handler --- app/Exceptions/Handler.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 5a53cd3..f9644ad 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -27,29 +27,14 @@ class Handler extends ExceptionHandler ]; /** - * Report or log an exception. + * Register the exception handling callbacks for the application. * - * @param \Throwable $exception * @return void - * - * @throws \Throwable - */ - public function report(Throwable $exception) - { - parent::report($exception); - } - - /** - * Render an exception into an HTTP response. - * - * @param \Illuminate\Http\Request $request - * @param \Throwable $exception - * @return \Symfony\Component\HttpFoundation\Response - * - * @throws \Throwable */ - public function render($request, Throwable $exception) + public function register() { - return parent::render($request, $exception); + $this->reportable(function (Throwable $e) { + // + }); } } From 77e2d8f96fae395b5b9bae6d313281c9e84d13e8 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 03/12] Shift HTTP kernel and middleware --- app/Http/Kernel.php | 7 +++---- ...ode.php => PreventRequestsDuringMaintenance.php} | 4 ++-- app/Http/Middleware/RedirectIfAuthenticated.php | 13 +++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) rename app/Http/Middleware/{CheckForMaintenanceMode.php => PreventRequestsDuringMaintenance.php} (58%) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 36ced13..21a8754 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -14,10 +14,10 @@ class Kernel extends HttpKernel * @var array */ protected $middleware = [ - // \App\Http\Middleware\TrustHosts::class, + \App\Http\Middleware\TrustHosts::class, \App\Http\Middleware\TrustProxies::class, \Fruitcake\Cors\HandleCors::class, - \App\Http\Middleware\CheckForMaintenanceMode::class, + \App\Http\Middleware\PreventRequestsDuringMaintenance::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, @@ -40,7 +40,7 @@ class Kernel extends HttpKernel ], 'api' => [ - 'throttle:60,1', + 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], ]; @@ -55,7 +55,6 @@ class Kernel extends HttpKernel protected $routeMiddleware = [ 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, diff --git a/app/Http/Middleware/CheckForMaintenanceMode.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php similarity index 58% rename from app/Http/Middleware/CheckForMaintenanceMode.php rename to app/Http/Middleware/PreventRequestsDuringMaintenance.php index 35b9824..e4956d0 100644 --- a/app/Http/Middleware/CheckForMaintenanceMode.php +++ b/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -2,9 +2,9 @@ namespace App\Http\Middleware; -use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware; +use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware; -class CheckForMaintenanceMode extends Middleware +class PreventRequestsDuringMaintenance extends Middleware { /** * The URIs that should be reachable while maintenance mode is enabled. diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 2395ddc..362b48b 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -4,6 +4,7 @@ use App\Providers\RouteServiceProvider; use Closure; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class RedirectIfAuthenticated @@ -13,13 +14,17 @@ class RedirectIfAuthenticated * * @param \Illuminate\Http\Request $request * @param \Closure $next - * @param string|null $guard + * @param string|null ...$guards * @return mixed */ - public function handle($request, Closure $next, $guard = null) + public function handle(Request $request, Closure $next, ...$guards) { - if (Auth::guard($guard)->check()) { - return redirect(RouteServiceProvider::HOME); + $guards = empty($guards) ? [null] : $guards; + + foreach ($guards as $guard) { + if (Auth::guard($guard)->check()) { + return redirect(RouteServiceProvider::HOME); + } } return $next($request); From 9c66cf550d8ef5de6146ae820d338d21f46c0eff Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 04/12] Shift service providers --- app/Providers/EventServiceProvider.php | 2 - app/Providers/RouteServiceProvider.php | 71 ++++++++++---------------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 723a290..a9f10a6 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -27,8 +27,6 @@ class EventServiceProvider extends ServiceProvider */ public function boot() { - parent::boot(); - // } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 540d17b..aa76156 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,26 +2,31 @@ namespace App\Providers; +use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\Route; class RouteServiceProvider extends ServiceProvider { /** - * This namespace is applied to your controller routes. + * The path to the "home" route for your application. * - * In addition, it is set as the URL generator's root namespace. + * This is used by Laravel authentication to redirect users after login. * * @var string */ - protected $namespace = 'App\Http\Controllers'; + public const HOME = '/home'; /** - * The path to the "home" route for your application. + * This namespace is applied to your controller routes. + * + * In addition, it is set as the URL generator's root namespace. * * @var string */ - public const HOME = '/home'; + protected $namespace = 'App\Http\Controllers'; /** * Define your route model bindings, pattern filters, etc. @@ -30,51 +35,29 @@ class RouteServiceProvider extends ServiceProvider */ public function boot() { - // - - parent::boot(); - } - - /** - * Define the routes for the application. - * - * @return void - */ - public function map() - { - $this->mapApiRoutes(); - - $this->mapWebRoutes(); - - // + $this->configureRateLimiting(); + + $this->routes(function () { + Route::prefix('api') + ->middleware('api') + ->namespace($this->namespace) + ->group(base_path('routes/api.php')); + + Route::middleware('web') + ->namespace($this->namespace) + ->group(base_path('routes/web.php')); + }); } /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware('web') - ->namespace($this->namespace) - ->group(base_path('routes/web.php')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. + * Configure the rate limiters for the application. * * @return void */ - protected function mapApiRoutes() + protected function configureRateLimiting() { - Route::prefix('api') - ->middleware('api') - ->namespace($this->namespace) - ->group(base_path('routes/api.php')); + RateLimiter::for('api', function (Request $request) { + return Limit::perMinute(60); + }); } } From b0f695cd1bc99fb8412d135d8c425b1ab2b3baef Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 05/12] Shift console routes --- routes/console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/console.php b/routes/console.php index da55196..e05f4c9 100644 --- a/routes/console.php +++ b/routes/console.php @@ -16,4 +16,4 @@ Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); -})->describe('Display an inspiring quote'); +})->purpose('Display an inspiring quote'); From b9b9f7f69d653292b0bd9fcaec3e37ce494b0a88 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 06/12] Ignore temporary framework files --- storage/framework/.gitignore | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore index b02b700..05c4471 100644 --- a/storage/framework/.gitignore +++ b/storage/framework/.gitignore @@ -1,8 +1,9 @@ +compiled.php config.php +down +events.scanned.php +maintenance.php routes.php +routes.scanned.php schedule-* -compiled.php services.json -events.scanned.php -routes.scanned.php -down From 008c21eca7ce7d2b34aa378413ee1ee680da1156 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 07/12] Shift to class based factories --- app/User.php | 3 +++ database/factories/UserFactory.php | 40 ++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/User.php b/app/User.php index e79dab7..1f24f91 100644 --- a/app/User.php +++ b/app/User.php @@ -2,12 +2,15 @@ namespace App; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { + use HasFactory; + use Notifiable; /** diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 741edea..42905fd 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -1,9 +1,11 @@ define(User::class, function (Faker $faker) { - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; -}); +class UserFactory extends Factory +{ + /** + * The name of the factory's corresponding model. + * + * @var string + */ + protected $model = User::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + 'name' => $this->faker->name, + 'email' => $this->faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } +} From 4a2db25b09868b5793f7e73a01e63a0013c73750 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:05 +0000 Subject: [PATCH 08/12] Namespace seeders --- database/{seeds => seeders}/DatabaseSeeder.php | 2 ++ 1 file changed, 2 insertions(+) rename database/{seeds => seeders}/DatabaseSeeder.php (89%) diff --git a/database/seeds/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php similarity index 89% rename from database/seeds/DatabaseSeeder.php rename to database/seeders/DatabaseSeeder.php index 237dfc5..8f55ce5 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -1,5 +1,7 @@ Date: Mon, 14 Dec 2020 22:43:06 +0000 Subject: [PATCH 09/12] Shift PSR-4 autoloading --- composer.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 8ff636e..4db408b 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,10 @@ }, "autoload": { "psr-4": { - "App\\": "app/" - }, - "classmap": [ - "database/seeds", - "database/factories" - ] + "App\\": "app/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/" + } }, "autoload-dev": { "psr-4": { From b6d066d9fa2b9482224f7b7332a3fa287e374924 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:06 +0000 Subject: [PATCH 10/12] Shift config files --- .env.example | 1 + config/broadcasting.php | 5 +++++ config/cache.php | 6 +++--- config/cors.php | 2 +- config/filesystems.php | 13 ------------- config/logging.php | 12 ++++++------ config/queue.php | 2 +- 7 files changed, 17 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index ac74863..7dc51e1 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ APP_DEBUG=true APP_URL=http://localhost LOG_CHANNEL=stack +LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 diff --git a/config/broadcasting.php b/config/broadcasting.php index 3bba110..ef20859 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -41,6 +41,11 @@ ], ], + 'ably' => [ + 'driver' => 'ably', + 'key' => env('ABLY_KEY'), + ], + 'redis' => [ 'driver' => 'redis', 'connection' => 'default', diff --git a/config/cache.php b/config/cache.php index 4f41fdf..9473acc 100644 --- a/config/cache.php +++ b/config/cache.php @@ -13,9 +13,6 @@ | using this caching library. This connection is used when another is | not explicitly specified when executing a given caching function. | - | Supported: "apc", "array", "database", "file", - | "memcached", "redis", "dynamodb" - | */ 'default' => env('CACHE_DRIVER', 'file'), @@ -29,6 +26,9 @@ | well as their drivers. You may even define multiple stores for the | same cache driver to group types of items stored in your caches. | + | Supported drivers: "apc", "array", "database", "file", + | "memcached", "redis", "dynamodb", "null" + | */ 'stores' => [ diff --git a/config/cors.php b/config/cors.php index 558369d..8a39e6d 100644 --- a/config/cors.php +++ b/config/cors.php @@ -15,7 +15,7 @@ | */ - 'paths' => ['api/*'], + 'paths' => ['api/*', 'sanctum/csrf-cookie'], 'allowed_methods' => ['*'], diff --git a/config/filesystems.php b/config/filesystems.php index 94c8112..10c9d9b 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -15,19 +15,6 @@ 'default' => env('FILESYSTEM_DRIVER', 'local'), - /* - |-------------------------------------------------------------------------- - | Default Cloud Filesystem Disk - |-------------------------------------------------------------------------- - | - | Many applications store files both locally and in the cloud. For this - | reason, you may specify a default "cloud" driver here. This driver - | will be bound as the Cloud disk implementation in the container. - | - */ - - 'cloud' => env('FILESYSTEM_CLOUD', 's3'), - /* |-------------------------------------------------------------------------- | Filesystem Disks diff --git a/config/logging.php b/config/logging.php index 088c204..6aa77fe 100644 --- a/config/logging.php +++ b/config/logging.php @@ -44,13 +44,13 @@ 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), - 'level' => 'debug', + 'level' => env('LOG_LEVEL', 'debug'), ], 'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), - 'level' => 'debug', + 'level' => env('LOG_LEVEL', 'debug'), 'days' => 14, ], @@ -59,12 +59,12 @@ 'url' => env('LOG_SLACK_WEBHOOK_URL'), 'username' => 'Laravel Log', 'emoji' => ':boom:', - 'level' => 'critical', + 'level' => env('LOG_LEVEL', 'critical'), ], 'papertrail' => [ 'driver' => 'monolog', - 'level' => 'debug', + 'level' => env('LOG_LEVEL', 'debug'), 'handler' => SyslogUdpHandler::class, 'handler_with' => [ 'host' => env('PAPERTRAIL_URL'), @@ -83,12 +83,12 @@ 'syslog' => [ 'driver' => 'syslog', - 'level' => 'debug', + 'level' => env('LOG_LEVEL', 'debug'), ], 'errorlog' => [ 'driver' => 'errorlog', - 'level' => 'debug', + 'level' => env('LOG_LEVEL', 'debug'), ], 'null' => [ diff --git a/config/queue.php b/config/queue.php index 00b76d6..1222296 100644 --- a/config/queue.php +++ b/config/queue.php @@ -81,7 +81,7 @@ */ 'failed' => [ - 'driver' => env('QUEUE_FAILED_DRIVER', 'database'), + 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 'database' => env('DB_CONNECTION', 'mysql'), 'table' => 'failed_jobs', ], From a765fe9bcc374a38b9a03cede6cdb46ce78599e3 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:06 +0000 Subject: [PATCH 11/12] Shift Laravel dependencies --- composer.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 4db408b..959271b 100644 --- a/composer.json +++ b/composer.json @@ -8,19 +8,19 @@ ], "license": "MIT", "require": { - "php": "^7.2.5|^8.0", + "php": "^7.3|^8.0", "fideloper/proxy": "^4.4", "fruitcake/laravel-cors": "^2.0", - "guzzlehttp/guzzle": "^6.3.1|^7.0.1", - "laravel/framework": "^7.29", + "guzzlehttp/guzzle": "^7.0.1", + "laravel/framework": "^8.18", "laravel/tinker": "^2.5" }, "require-dev": { - "facade/ignition": "^2.0", + "facade/ignition": "^2.5", "fakerphp/faker": "^1.9.1", - "mockery/mockery": "^1.3.1", - "nunomaduro/collision": "^4.3", - "phpunit/phpunit": "^8.5.8|^9.3.3" + "mockery/mockery": "^1.4.2", + "nunomaduro/collision": "^5.0", + "phpunit/phpunit": "^9.3.3" }, "config": { "optimize-autoloader": true, From 3f42e37900f26ffb5275712a2475f8b4b9d7a520 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Mon, 14 Dec 2020 22:43:07 +0000 Subject: [PATCH 12/12] Shift cleanup --- app/User.php | 3 +-- database/factories/UserFactory.php | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/User.php b/app/User.php index 1f24f91..c5a1d87 100644 --- a/app/User.php +++ b/app/User.php @@ -2,15 +2,14 @@ namespace App; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Contracts\Auth\MustVerifyEmail; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use HasFactory; - use Notifiable; /** diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 42905fd..f4d35f1 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -1,11 +1,9 @@