Upgrade to Laravel 8

This commit is contained in:
Jonathan Reinink 2020-09-08 18:45:49 -04:00
parent 680826b072
commit 15b761208e
35 changed files with 1226 additions and 942 deletions

View File

@ -3,7 +3,6 @@
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
@ -27,29 +26,12 @@ class Handler extends ExceptionHandler
];
/**
* Report or log an exception.
* Register the exception handling callbacks for the application.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
public function register()
{
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)
{
return parent::render($request, $exception);
//
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@ -3,8 +3,8 @@
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
class LoginController extends Controller
@ -27,8 +27,13 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/';
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Show the application's login form.
*
* @return \Inertia\Response
*/
public function showLoginForm()
{
return Inertia::render('Auth/Login');

View File

@ -1,72 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}

View File

@ -1,41 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Contact;
use App\Models\Contact;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;

View File

@ -6,7 +6,7 @@ use Inertia\Inertia;
class DashboardController extends Controller
{
public function __invoke()
public function index()
{
return Inertia::render('Dashboard/Index');
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Organization;
use App\Models\Organization;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;

View File

@ -6,7 +6,7 @@ use Inertia\Inertia;
class ReportsController extends Controller
{
public function __invoke()
public function index()
{
return Inertia::render('Reports/Index');
}

View File

@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\User;
use App\Models\User;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

View File

@ -17,7 +17,7 @@ class Kernel extends HttpKernel
// \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,

View File

@ -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.

View File

@ -13,14 +13,18 @@ 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, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}

View File

@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models;
class Account extends Model
{

View File

@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;

View File

@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;

View File

@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;

View File

@ -1,6 +1,6 @@
<?php
namespace App;
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;

View File

@ -27,8 +27,6 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot()
{
parent::boot();
//
}
}

View File

@ -2,26 +2,22 @@
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.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/home';
public const HOME = '/';
/**
* Define your route model bindings, pattern filters, etc.
@ -30,51 +26,27 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
//
$this->configureRateLimiting();
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60);
});
}
}

View File

@ -8,22 +8,23 @@
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"php": "^7.3.0",
"ext-exif": "*",
"ext-gd": "*",
"facade/ignition": "^2.0",
"facade/ignition": "^2.3.6",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"fzaninotto/faker": "^1.9.1",
"guzzlehttp/guzzle": "^6.3",
"guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.2",
"laravel/framework": "^7.22.2",
"laravel/framework": "^8.0",
"laravel/legacy-factories": "^1.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.0",
"league/glide": "2.0.x-dev",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3",
"reinink/remember-query-strings": "^0.1.0",
"tightenco/ziggy": "^0.8.0"
},

1641
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ return [
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
'model' => App\Models\User::class,
],
// 'users' => [

View File

@ -81,7 +81,7 @@ return [
*/
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],

View File

@ -2,7 +2,7 @@
use Faker\Generator as Faker;
$factory->define(App\Contact::class, function (Faker $faker) {
$factory->define(App\Models\Contact::class, function (Faker $faker) {
return [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,

View File

@ -2,7 +2,7 @@
use Faker\Generator as Faker;
$factory->define(App\Organization::class, function (Faker $faker) {
$factory->define(App\Models\Organization::class, function (Faker $faker) {
return [
'name' => $faker->company,
'email' => $faker->companyEmail,

View File

@ -14,7 +14,7 @@ use Illuminate\Support\Str;
|
*/
$factory->define(App\User::class, function (Faker $faker) {
$factory->define(App\Models\User::class, function (Faker $faker) {
return [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,

View File

@ -1,9 +1,9 @@
<?php
use App\Account;
use App\Contact;
use App\Organization;
use App\User;
use App\Models\Account;
use App\Models\Contact;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder

View File

@ -12,15 +12,16 @@
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</include>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>

View File

@ -13,6 +13,6 @@ use Illuminate\Support\Facades\Broadcast;
|
*/
Broadcast::channel('App.User.{id}', function ($user, $id) {
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

View File

@ -16,4 +16,4 @@ use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');
})->purpose('Display an inspiring quote');

View File

@ -1,5 +1,11 @@
<?php
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\ContactsController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\OrganizationsController;
use App\Http\Controllers\ReportsController;
use App\Http\Controllers\UsersController;
use Illuminate\Support\Facades\Route;
/*
@ -14,47 +20,126 @@ use Illuminate\Support\Facades\Route;
*/
// Auth
Route::get('login')->name('login')->uses('Auth\LoginController@showLoginForm')->middleware('guest');
Route::post('login')->name('login.attempt')->uses('Auth\LoginController@login')->middleware('guest');
Route::post('logout')->name('logout')->uses('Auth\LoginController@logout');
Route::get('login', [LoginController::class, 'showLoginForm'])
->name('login')
->middleware('guest');
Route::post('login', [LoginController::class, 'login'])
->name('login.attempt')
->middleware('guest');
Route::post('logout', [LoginController::class, 'logout'])
->name('logout');
// Dashboard
Route::get('/')->name('dashboard')->uses('DashboardController')->middleware('auth');
Route::get('/', [DashboardController::class, 'index'])
->name('dashboard')
->middleware('auth');
// Users
Route::get('users')->name('users')->uses('UsersController@index')->middleware('remember', 'auth');
Route::get('users/create')->name('users.create')->uses('UsersController@create')->middleware('auth');
Route::post('users')->name('users.store')->uses('UsersController@store')->middleware('auth');
Route::get('users/{user}/edit')->name('users.edit')->uses('UsersController@edit')->middleware('auth');
Route::put('users/{user}')->name('users.update')->uses('UsersController@update')->middleware('auth');
Route::delete('users/{user}')->name('users.destroy')->uses('UsersController@destroy')->middleware('auth');
Route::put('users/{user}/restore')->name('users.restore')->uses('UsersController@restore')->middleware('auth');
// Images
Route::get('/img/{path}', 'ImagesController@show')->where('path', '.*');
Route::get('users', [UsersController::class, 'index'])
->name('users')
->middleware('remember', 'auth');
Route::get('users/create', [UsersController::class, 'create'])
->name('users.create')
->middleware('auth');
Route::post('users', [UsersController::class, 'store'])
->name('users.store')
->middleware('auth');
Route::get('users/{user}/edit', [UsersController::class, 'edit'])
->name('users.edit')
->middleware('auth');
Route::put('users/{user}', [UsersController::class, 'update'])
->name('users.update')
->middleware('auth');
Route::delete('users/{user}', [UsersController::class, 'destroy'])
->name('users.destroy')
->middleware('auth');
Route::put('users/{user}/restore', [UsersController::class, 'restore'])
->name('users.restore')
->middleware('auth');
// Organizations
Route::get('organizations')->name('organizations')->uses('OrganizationsController@index')->middleware('remember', 'auth');
Route::get('organizations/create')->name('organizations.create')->uses('OrganizationsController@create')->middleware('auth');
Route::post('organizations')->name('organizations.store')->uses('OrganizationsController@store')->middleware('auth');
Route::get('organizations/{organization}/edit')->name('organizations.edit')->uses('OrganizationsController@edit')->middleware('auth');
Route::put('organizations/{organization}')->name('organizations.update')->uses('OrganizationsController@update')->middleware('auth');
Route::delete('organizations/{organization}')->name('organizations.destroy')->uses('OrganizationsController@destroy')->middleware('auth');
Route::put('organizations/{organization}/restore')->name('organizations.restore')->uses('OrganizationsController@restore')->middleware('auth');
Route::get('organizations', [OrganizationsController::class, 'index'])
->name('organizations')
->middleware('remember', 'auth');
Route::get('organizations/create', [OrganizationsController::class, 'create'])
->name('organizations.create')
->middleware('auth');
Route::post('organizations', [OrganizationsController::class, 'store'])
->name('organizations.store')
->middleware('auth');
Route::get('organizations/{organization}/edit', [OrganizationsController::class, 'edit'])
->name('organizations.edit')
->middleware('auth');
Route::put('organizations/{organization}', [OrganizationsController::class, 'update'])
->name('organizations.update')
->middleware('auth');
Route::delete('organizations/{organization}', [OrganizationsController::class, 'destroy'])
->name('organizations.destroy')
->middleware('auth');
Route::put('organizations/{organization}/restore', [OrganizationsController::class, 'restore'])
->name('organizations.restore')
->middleware('auth');
// Contacts
Route::get('contacts')->name('contacts')->uses('ContactsController@index')->middleware('remember', 'auth');
Route::get('contacts/create')->name('contacts.create')->uses('ContactsController@create')->middleware('auth');
Route::post('contacts')->name('contacts.store')->uses('ContactsController@store')->middleware('auth');
Route::get('contacts/{contact}/edit')->name('contacts.edit')->uses('ContactsController@edit')->middleware('auth');
Route::put('contacts/{contact}')->name('contacts.update')->uses('ContactsController@update')->middleware('auth');
Route::delete('contacts/{contact}')->name('contacts.destroy')->uses('ContactsController@destroy')->middleware('auth');
Route::put('contacts/{contact}/restore')->name('contacts.restore')->uses('ContactsController@restore')->middleware('auth');
Route::get('contacts', [ContactsController::class, 'index'])
->name('contacts')
->middleware('remember', 'auth');
Route::get('contacts/create', [ContactsController::class, 'create'])
->name('contacts.create')
->middleware('auth');
Route::post('contacts', [ContactsController::class, 'store'])
->name('contacts.store')
->middleware('auth');
Route::get('contacts/{contact}/edit', [ContactsController::class, 'edit'])
->name('contacts.edit')
->middleware('auth');
Route::put('contacts/{contact}', [ContactsController::class, 'update'])
->name('contacts.update')
->middleware('auth');
Route::delete('contacts/{contact}', [ContactsController::class, 'destroy'])
->name('contacts.destroy')
->middleware('auth');
Route::put('contacts/{contact}/restore', [ContactsController::class, 'restore'])
->name('contacts.restore')
->middleware('auth');
// Reports
Route::get('reports')->name('reports')->uses('ReportsController')->middleware('auth');
Route::get('reports', [ReportsController::class, 'index'])
->name('reports')
->middleware('auth');
// Images
Route::get('/img/{path}', 'ImagesController@show')->where('path', '.*');
// 500 error
Route::get('500', function () {
// Force debug mode for this endpoint in the demo environment
if (App::environment('demo')) {

View File

@ -2,9 +2,9 @@
namespace Tests\Feature;
use App\Account;
use App\Contact;
use App\User;
use App\Models\Account;
use App\Models\Contact;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

View File

@ -2,9 +2,9 @@
namespace Tests\Feature;
use App\Account;
use App\Organization;
use App\User;
use App\Models\Account;
use App\Models\User;
use App\Models\Organization;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;