Skip to content

Commit ae60969

Browse files
driesvintslaravel-shiftjoedixon
authored
Laravel 8.x Shift (#563)
* Adopt Laravel coding style The Laravel framework adopts the PSR-2 coding style with some additions. Laravel apps *should* adopt this coding style as well. However, Shift allows you to customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config to your project. You may use [Shift's .php_cs][2] file as a base. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 * Shift HTTP kernel and middleware * Shift console routes * Ignore temporary framework files * Shift to class based factories * Namespace seeders * Shift PSR-4 autoloading * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them. This allows you to review the commit diff for once for customizations when you are done Shifting. Moving forward, consider using ENV variables or create a separate config file to allow the core config files to remain as default as possible. * Shift Laravel dependencies * Shift cleanup * Apply fixes from StyleCI * Update dependencies * Update index.php * Update exception handler * Update auth redirect * Update route service provider * Fix factory migration * Add uuid to failed jobs table * Migrate phpiunit configuration * Republish horizon assets * Apply fixes from StyleCI * Update routes * Fix indentation * Remove route namespace * Update faker * Remove down method * Apply fixes from StyleCI * Update phpunit configuration * Fix formatting Co-authored-by: Laravel Shift <[email protected]> Co-authored-by: Dries Vints <[email protected]> Co-authored-by: Joe Dixon <[email protected]> Co-authored-by: Joe Dixon <[email protected]>
1 parent bd4ebce commit ae60969

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3075
-2124
lines changed

app/Exceptions/Handler.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Illuminate\Session\TokenMismatchException;
1010
use Illuminate\Validation\ValidationException;
1111
use Symfony\Component\HttpKernel\Exception\HttpException;
12-
use Throwable;
1312

1413
class Handler extends ExceptionHandler
1514
{
@@ -38,23 +37,12 @@ class Handler extends ExceptionHandler
3837
];
3938

4039
/**
41-
* Report or log an exception.
40+
* Register the exception handling callbacks for the application.
4241
*
43-
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
42+
* @return void
4443
*/
45-
public function report(Throwable $exception)
44+
public function register()
4645
{
47-
parent::report($exception);
48-
}
49-
50-
/**
51-
* Render an exception into an HTTP response.
52-
*
53-
* @param \Illuminate\Http\Request $request
54-
* @return \Symfony\Component\HttpFoundation\Response
55-
*/
56-
public function render($request, Throwable $exception)
57-
{
58-
return parent::render($request, $exception);
46+
//
5947
}
6048
}

app/Http/Kernel.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Kernel extends HttpKernel
1616
protected $middleware = [
1717
\App\Http\Middleware\TrustProxies::class,
1818
\Fruitcake\Cors\HandleCors::class,
19-
\App\Http\Middleware\CheckForMaintenanceMode::class,
19+
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
2020
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
2121
\App\Http\Middleware\TrimStrings::class,
2222
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
@@ -40,7 +40,7 @@ class Kernel extends HttpKernel
4040
],
4141

4242
'api' => [
43-
'throttle:60,1',
43+
'throttle:api',
4444
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4545
],
4646
];
@@ -55,7 +55,6 @@ class Kernel extends HttpKernel
5555
protected $routeMiddleware = [
5656
'auth' => \App\Http\Middleware\Authenticate::class,
5757
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
58-
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
5958
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
6059
'can' => \Illuminate\Auth\Middleware\Authorize::class,
6160
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,

app/Http/Middleware/CheckForMaintenanceMode.php renamed to app/Http/Middleware/PreventRequestsDuringMaintenance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace App\Http\Middleware;
44

5-
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
5+
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
66

7-
class CheckForMaintenanceMode extends Middleware
7+
class PreventRequestsDuringMaintenance extends Middleware
88
{
99
/**
1010
* The URIs that should be reachable while maintenance mode is enabled.

app/Http/Middleware/RedirectIfAuthenticated.php

Lines changed: 9 additions & 4 deletions
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()->route('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/Http/Middleware/TrustHosts.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Illuminate\Http\Middleware\TrustHosts as Middleware;
6+
7+
class TrustHosts extends Middleware
8+
{
9+
/**
10+
* Get the host patterns that should be trusted.
11+
*
12+
* @return array
13+
*/
14+
public function hosts()
15+
{
16+
return [
17+
$this->allSubdomainsOfApplicationUrl(),
18+
];
19+
}
20+
}

app/Models/Article.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
use App\Helpers\PreparesSearch;
1111
use Carbon\Carbon;
1212
use Illuminate\Database\Eloquent\Builder;
13+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1314
use Illuminate\Database\Eloquent\Model;
1415
use Illuminate\Support\Str;
1516
use Laravel\Scout\Searchable;
1617

1718
final class Article extends Model
1819
{
20+
use HasFactory;
1921
use HasAuthor;
2022
use HasSlug;
2123
use HasLikes;
@@ -231,7 +233,7 @@ public function scopeTrending(Builder $query): Builder
231233
->orderBy('submitted_at', 'desc');
232234
}
233235

234-
public function previousInSeries(): ?Article
236+
public function previousInSeries(): ?self
235237
{
236238
return $this->series
237239
->articles()
@@ -241,7 +243,7 @@ public function previousInSeries(): ?Article
241243
->first();
242244
}
243245

244-
public function nextInSeries(): ?Article
246+
public function nextInSeries(): ?self
245247
{
246248
return $this->series
247249
->articles()

app/Models/Like.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace App\Models;
44

5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
56
use Illuminate\Database\Eloquent\Model;
67

78
final class Like extends Model
89
{
10+
use HasFactory;
11+
912
protected $fillable = ['user_id'];
1013
}

app/Models/Reply.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use App\Helpers\HasLikes;
77
use App\Helpers\HasTimestamps;
88
use App\Helpers\ModelHelpers;
9+
use Illuminate\Database\Eloquent\Factories\HasFactory;
910
use Illuminate\Database\Eloquent\Model;
1011
use Illuminate\Database\Eloquent\Relations\MorphTo;
1112
use Illuminate\Support\Str;
1213

1314
final class Reply extends Model
1415
{
16+
use HasFactory;
1517
use HasAuthor;
1618
use HasLikes;
1719
use HasTimestamps;

app/Models/Series.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
use App\Helpers\HasAuthor;
66
use App\Helpers\HasSlug;
77
use App\Helpers\HasTags;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
910

1011
class Series extends Model
1112
{
13+
use HasFactory;
1214
use HasAuthor;
1315
use HasTags;
1416
use HasSlug;

app/Models/Subscription.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
use App\Helpers\HasUuid;
66
use App\User;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\BelongsTo;
910
use Illuminate\Database\Eloquent\Relations\MorphTo;
1011

1112
final class Subscription extends Model
1213
{
14+
use HasFactory;
1315
use HasUuid;
1416

1517
/**

app/Models/Tag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use App\Helpers\HasSlug;
66
use App\Helpers\ModelHelpers;
7+
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\MorphToMany;
910

1011
final class Tag extends Model
1112
{
13+
use HasFactory;
1214
use HasSlug;
1315
use ModelHelpers;
1416

app/Models/Thread.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Contracts\Pagination\Paginator;
1717
use Illuminate\Database\Eloquent\Builder;
1818
use Illuminate\Database\Eloquent\Collection;
19+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1920
use Illuminate\Database\Eloquent\Model;
2021
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2122
use Illuminate\Support\Carbon;
@@ -28,6 +29,7 @@
2829

2930
final class Thread extends Model implements ReplyAble, SubscriptionAble, Feedable
3031
{
32+
use HasFactory;
3133
use HasAuthor;
3234
use HasLikes;
3335
use HasSlug;

app/Providers/RouteServiceProvider.php

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,54 @@
22

33
namespace App\Providers;
44

5+
use Illuminate\Cache\RateLimiting\Limit;
56
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7+
use Illuminate\Support\Facades\RateLimiter;
68
use Illuminate\Support\Facades\Route;
79

810
class RouteServiceProvider extends ServiceProvider
911
{
10-
/**
11-
* This namespace is applied to your controller routes.
12-
*
13-
* In addition, it is set as the URL generator's root namespace.
14-
*
15-
* @var string
16-
*/
17-
protected $namespace = 'App\Http\Controllers';
18-
1912
/**
2013
* The path to the "home" route for your application.
2114
*
15+
* This is used by Laravel authentication to redirect users after login.
16+
*
2217
* @var string
2318
*/
2419
public const HOME = '/dashboard';
2520

2621
/**
2722
* Define your route model bindings, pattern filters, etc.
23+
*
24+
* @return void
2825
*/
2926
public function boot()
3027
{
31-
require base_path('routes/bindings.php');
32-
33-
parent::boot();
34-
}
28+
$this->configureRateLimiting();
3529

36-
/**
37-
* Define the routes for the application.
38-
*/
39-
public function map()
40-
{
41-
$this->mapApiRoutes();
42-
43-
$this->mapWebRoutes();
30+
require base_path('routes/bindings.php');
4431

45-
//
46-
}
32+
$this->routes(function () {
33+
Route::prefix('api')
34+
->middleware('api')
35+
->namespace($this->namespace)
36+
->group(base_path('routes/api.php'));
4737

48-
/**
49-
* Define the "web" routes for the application.
50-
*
51-
* These routes all receive session state, CSRF protection, etc.
52-
*/
53-
protected function mapWebRoutes()
54-
{
55-
Route::middleware('web')
56-
->namespace($this->namespace)
57-
->group(base_path('routes/web.php'));
38+
Route::middleware('web')
39+
->namespace($this->namespace)
40+
->group(base_path('routes/web.php'));
41+
});
5842
}
5943

6044
/**
61-
* Define the "api" routes for the application.
45+
* Configure the rate limiters for the application.
6246
*
63-
* These routes are typically stateless.
47+
* @return void
6448
*/
65-
protected function mapApiRoutes()
49+
protected function configureRateLimiting()
6650
{
67-
Route::prefix('api')
68-
->middleware('api')
69-
->namespace($this->namespace)
70-
->group(base_path('routes/api.php'));
51+
RateLimiter::for('api', function (Request $request) {
52+
return Limit::perMinute(60);
53+
});
7154
}
7255
}

app/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use App\Models\Series;
1010
use App\Models\Thread;
1111
use Illuminate\Contracts\Auth\MustVerifyEmail;
12+
use Illuminate\Database\Eloquent\Factories\HasFactory;
1213
use Illuminate\Database\Eloquent\Relations\HasMany;
1314
use Illuminate\Foundation\Auth\User as Authenticatable;
1415
use Illuminate\Notifications\Notifiable;
1516
use Illuminate\Support\Facades\Auth;
1617

1718
final class User extends Authenticatable implements MustVerifyEmail
1819
{
20+
use HasFactory;
1921
use HasTimestamps;
2022
use ModelHelpers;
2123
use Notifiable;

0 commit comments

Comments
 (0)