Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 4d7c1d7

Browse files
committed
upgrade Laravel to v8
1 parent 5b0b9ea commit 4d7c1d7

29 files changed

+835
-1459
lines changed

.gitignore

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/node_modules
2+
/public/hot
23
/public/storage
4+
/storage/*.key
35
/vendor
4-
/.idea
6+
.env
7+
.env.backup
8+
.phpunit.result.cache
59
Homestead.json
610
Homestead.yaml
7-
.env
11+
npm-debug.log
12+
yarn-error.log

app/Data/Models/User.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace App\Data\Models;
44

55
use Illuminate\Notifications\Notifiable;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Foundation\Auth\User as Authenticatable;
78

89
class User extends Authenticatable
910
{
10-
use Notifiable;
11+
use HasFactory, Notifiable;
1112

1213
/**
1314
* The attributes that are mass assignable.
@@ -26,4 +27,13 @@ class User extends Authenticatable
2627
protected $hidden = [
2728
'password', 'remember_token',
2829
];
30+
31+
/**
32+
* The attributes that should be cast to native types.
33+
*
34+
* @var array
35+
*/
36+
protected $casts = [
37+
'email_verified_at' => 'datetime',
38+
];
2939
}

app/Exceptions/Handler.php

+12-19
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,36 @@
22

33
namespace App\Exceptions;
44

5-
use Throwable;
65
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
76

87
class Handler extends ExceptionHandler
98
{
109
/**
11-
* A list of the exception types that should not be reported.
10+
* A list of the exception types that are not reported.
1211
*
1312
* @var array
1413
*/
1514
protected $dontReport = [
15+
//
1616
];
1717

1818
/**
19-
* Report or log an exception.
19+
* A list of the inputs that are never flashed for validation exceptions.
2020
*
21-
* @param \Throwable $exception
22-
* @return void
23-
*
24-
* @throws \Throwable
21+
* @var array
2522
*/
26-
public function report(Throwable $exception)
27-
{
28-
parent::report($exception);
29-
}
23+
protected $dontFlash = [
24+
'password',
25+
'password_confirmation',
26+
];
3027

3128
/**
32-
* Render an exception into an HTTP response.
29+
* Register the exception handling callbacks for the application.
3330
*
34-
* @param \Illuminate\Http\Request $request
35-
* @param \Throwable $exception
36-
* @return \Symfony\Component\HttpFoundation\Response
37-
*
38-
* @throws \Throwable
31+
* @return void
3932
*/
40-
public function render($request, Throwable $exception)
33+
public function register()
4134
{
42-
return parent::render($request, $exception);
35+
//
4336
}
4437
}

app/Http/Kernel.php

+6-21
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ class Kernel extends HttpKernel
1414
* @var array
1515
*/
1616
protected $middleware = [
17-
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
17+
// \App\Http\Middleware\TrustHosts::class,
18+
\App\Http\Middleware\TrustProxies::class,
1819
\Fruitcake\Cors\HandleCors::class,
20+
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
1921
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
2022
\App\Http\Middleware\TrimStrings::class,
2123
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
@@ -38,8 +40,8 @@ class Kernel extends HttpKernel
3840
],
3941

4042
'api' => [
41-
'throttle:60,1',
42-
'bindings',
43+
'throttle:api',
44+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4345
],
4446
];
4547

@@ -53,29 +55,12 @@ class Kernel extends HttpKernel
5355
protected $routeMiddleware = [
5456
'auth' => \App\Http\Middleware\Authenticate::class,
5557
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
56-
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
5758
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
5859
'can' => \Illuminate\Auth\Middleware\Authorize::class,
5960
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
61+
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
6062
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
6163
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6264
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
63-
];
64-
65-
/**
66-
* The priority-sorted list of middleware.
67-
*
68-
* This forces the listed middleware to always be in the given order.
69-
*
70-
* @var array
71-
*/
72-
protected $middlewarePriority = [
73-
\Illuminate\Session\Middleware\StartSession::class,
74-
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
75-
\Framework\Http\Middleware\Authenticate::class,
76-
\Illuminate\Routing\Middleware\ThrottleRequests::class,
77-
\Illuminate\Session\Middleware\AuthenticateSession::class,
78-
\Illuminate\Routing\Middleware\SubstituteBindings::class,
79-
\Illuminate\Auth\Middleware\Authorize::class,
8065
];
8166
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
6+
7+
class PreventRequestsDuringMaintenance extends Middleware
8+
{
9+
/**
10+
* The URIs that should be reachable while maintenance mode is enabled.
11+
*
12+
* @var array
13+
*/
14+
protected $except = [
15+
//
16+
];
17+
}

app/Http/Middleware/RedirectIfAuthenticated.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Middleware;
44

5+
use App\Providers\RouteServiceProvider;
56
use Closure;
67
use Illuminate\Support\Facades\Auth;
78

@@ -12,13 +13,17 @@ class RedirectIfAuthenticated
1213
*
1314
* @param \Illuminate\Http\Request $request
1415
* @param \Closure $next
15-
* @param string|null $guard
16+
* @param string|null ...$guards
1617
* @return mixed
1718
*/
18-
public function handle($request, Closure $next, $guard = null)
19+
public function handle($request, Closure $next, ...$guards)
1920
{
20-
if (Auth::guard($guard)->check()) {
21-
return redirect('/home');
21+
$guards = empty($guards) ? [null] : $guards;
22+
23+
foreach ($guards as $guard) {
24+
if (Auth::guard($guard)->check()) {
25+
return redirect(RouteServiceProvider::HOME);
26+
}
2227
}
2328

2429
return $next($request);

app/Providers/AuthServiceProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Providers;
44

5-
use Illuminate\Support\Facades\Gate;
65
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
6+
use Illuminate\Support\Facades\Gate;
77

88
class AuthServiceProvider extends ServiceProvider
99
{
@@ -13,7 +13,7 @@ class AuthServiceProvider extends ServiceProvider
1313
* @var array
1414
*/
1515
protected $policies = [
16-
'App\Model' => 'App\Policies\ModelPolicy',
16+
// 'App\Data\Models\Model' => 'App\Policies\ModelPolicy',
1717
];
1818

1919
/**

app/Providers/EventServiceProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Providers;
44

5-
use Illuminate\Support\Facades\Event;
65
use Illuminate\Auth\Events\Registered;
76
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
87
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
8+
use Illuminate\Support\Facades\Event;
99

1010
class EventServiceProvider extends ServiceProvider
1111
{
@@ -27,8 +27,6 @@ class EventServiceProvider extends ServiceProvider
2727
*/
2828
public function boot()
2929
{
30-
parent::boot();
31-
3230
//
3331
}
3432
}

app/Providers/RouteServiceProvider.php

+27-43
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,62 @@
22

33
namespace App\Providers;
44

5-
use Illuminate\Support\Facades\Route;
5+
use Illuminate\Cache\RateLimiting\Limit;
66
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\RateLimiter;
9+
use Illuminate\Support\Facades\Route;
710

811
class RouteServiceProvider extends ServiceProvider
912
{
1013
/**
11-
* This namespace is applied to your controller routes.
14+
* The path to the "home" route for your application.
1215
*
13-
* In addition, it is set as the URL generator's root namespace.
16+
* This is used by Laravel authentication to redirect users after login.
1417
*
1518
* @var string
1619
*/
17-
protected $namespace = 'App\Http\Controllers';
20+
public const HOME = '/home';
1821

1922
/**
20-
* Define your route model bindings, pattern filters, etc.
23+
* The controller namespace for the application.
2124
*
22-
* @return void
25+
* When present, controller route declarations will automatically be prefixed with this namespace.
26+
*
27+
* @var string|null
2328
*/
24-
public function boot()
25-
{
26-
//
27-
28-
parent::boot();
29-
}
29+
// protected $namespace = 'App\\Http\\Controllers';
3030

3131
/**
32-
* Define the routes for the application.
32+
* Define your route model bindings, pattern filters, etc.
3333
*
3434
* @return void
3535
*/
36-
public function map()
36+
public function boot()
3737
{
38-
$this->mapWebRoutes();
39-
40-
$this->mapApiRoutes();
38+
$this->configureRateLimiting();
4139

42-
//
43-
}
40+
$this->routes(function () {
41+
Route::prefix('api')
42+
->middleware('api')
43+
->namespace($this->namespace)
44+
->group(base_path('routes/api.php'));
4445

45-
/**
46-
* Define the "web" routes for the application.
47-
*
48-
* These routes all receive session state, CSRF protection, etc.
49-
*
50-
* @return void
51-
*/
52-
protected function mapWebRoutes()
53-
{
54-
Route::group([
55-
'middleware' => 'web',
56-
'namespace' => $this->namespace,
57-
], function ($router) {
58-
require base_path('routes/web.php');
46+
Route::middleware('web')
47+
->namespace($this->namespace)
48+
->group(base_path('routes/web.php'));
5949
});
6050
}
6151

6252
/**
63-
* Define the "api" routes for the application.
64-
*
65-
* These routes are typically stateless.
53+
* Configure the rate limiters for the application.
6654
*
6755
* @return void
6856
*/
69-
protected function mapApiRoutes()
57+
protected function configureRateLimiting()
7058
{
71-
Route::group([
72-
'middleware' => 'api',
73-
'namespace' => $this->namespace,
74-
'prefix' => 'api',
75-
], function ($router) {
76-
require base_path('routes/api.php');
59+
RateLimiter::for('api', function (Request $request) {
60+
return Limit::perMinute(60);
7761
});
7862
}
7963
}

artisan

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env php
22
<?php
33

4+
define('LARAVEL_START', microtime(true));
5+
46
/*
57
|--------------------------------------------------------------------------
68
| Register The Auto Loader
@@ -13,7 +15,7 @@
1315
|
1416
*/
1517

16-
require __DIR__.'/bootstrap/autoload.php';
18+
require __DIR__.'/vendor/autoload.php';
1719

1820
$app = require_once __DIR__.'/bootstrap/app.php';
1921

@@ -40,7 +42,7 @@ $status = $kernel->handle(
4042
| Shutdown The Application
4143
|--------------------------------------------------------------------------
4244
|
43-
| Once Artisan has finished running. We will fire off the shutdown events
45+
| Once Artisan has finished running, we will fire off the shutdown events
4446
| so that any final work may be done by the application before we shut
4547
| down the process. This is the last thing to happen to the request.
4648
|

0 commit comments

Comments
 (0)