Skip to content

Commit

Permalink
V3 - Laravel 8 base (#54)
Browse files Browse the repository at this point in the history
Updates to base files
Rework various things to be up to date with the latest best pracise
Improvements to testing
Addressing tech debt
  • Loading branch information
specialtactics authored Jun 5, 2021
1 parent 1fdfd29 commit 2efaae3
Show file tree
Hide file tree
Showing 48 changed files with 9,800 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ indent_size = 2

[*.{js,json}]
indent_style = space
indent_size = 2
indent_size = 4
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ JWT_SECRET=
JWT_TTL=1440

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=your_project_postgres
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/node_modules
/public/hot
/public/storage
/storage/*.index
/storage/*.key
storage/laradock
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml

Homestead.json
Homestead.yaml
Expand All @@ -17,4 +20,4 @@ yarn-error.log
/.vagrant
.phpstorm*
_ide_helper.php
.DS_Store
.DS_Store
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ matrix:
fast_finish: true
include:
- php: 7.3
env: LARAVEL_VERSION=7.*
env: LARAVEL_VERSION=8.*
- php: 7.4
env: LARAVEL_VERSION=7.*
env: LARAVEL_VERSION=8.*

sudo: false

Expand Down
3 changes: 1 addition & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
// $schedule->command('inspire')->hourly();
}

/**
Expand Down
24 changes: 6 additions & 18 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,20 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];

/**
* 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)
{
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param Throwable $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Throwable $exception)
public function register()
{
return parent::render($request, $exception);
$this->reportable(function (Throwable $e) {
//
});
}
}
23 changes: 3 additions & 20 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
// \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,
Expand All @@ -40,7 +41,7 @@ class Kernel extends HttpKernel

'api' => [
'snake_case',
'throttle:60,1',
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
Expand All @@ -55,7 +56,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,
Expand All @@ -66,21 +66,4 @@ class Kernel extends HttpKernel
'snake_case' => \Specialtactics\L5Api\Http\Middleware\SnakeCaseInputParameterKeys::class,
'check_role' => \Specialtactics\L5Api\Http\Middleware\CheckUserRole::class,
];

/**
* The priority-sorted list of middleware.
*
* This forces non-global middleware to always be in the given order.
*
* @var array
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\Authenticate::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class,
\Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
];
}
17 changes: 17 additions & 0 deletions app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;

class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}
13 changes: 9 additions & 4 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/TrimStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TrimStrings extends Middleware
* @var array
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Middleware/TrustHosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TrustProxies extends Middleware
/**
* The trusted proxies for this application.
*
* @var array|string
* @var array|string|null
*/
protected $proxies;

Expand All @@ -19,5 +19,5 @@ class TrustProxies extends Middleware
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_ALL;
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
}
15 changes: 10 additions & 5 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Models;

use App\Models\Role;
use Hash;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
Expand All @@ -19,7 +19,7 @@ class User extends BaseModel implements
CanResetPasswordContract,
JWTSubject
{
use Authenticatable, Authorizable, CanResetPassword, Notifiable;
use Authenticatable, Authorizable, CanResetPassword, HasFactory, Notifiable;

/**
* @var int Auto increments integer key
Expand All @@ -37,16 +37,21 @@ class User extends BaseModel implements
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'primary_role',
'name',
'email',
'password',
'primary_role',
];

/**
* The attributes that should be hidden for arrays and API output
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'email_verified_at', 'primary_role',
'password',
'remember_token',
'email_verified_at',
];

/**
Expand Down
2 changes: 0 additions & 2 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class EventServiceProvider extends ServiceProvider
*/
public function boot()
{
parent::boot();

//
}
}
Loading

0 comments on commit 2efaae3

Please sign in to comment.