Skip to content

Commit

Permalink
Laravel 11 base updates
Browse files Browse the repository at this point in the history
  • Loading branch information
specialtactics committed Jan 28, 2025
1 parent 7e347bb commit 857e446
Show file tree
Hide file tree
Showing 42 changed files with 698 additions and 858 deletions.
72 changes: 36 additions & 36 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
###########################################################
#################### Laravel Configuration ################
###########################################################

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

# API Settings
API_SUBTYPE=Laravel
API_DOMAIN=localhost
API_DEBUG=true
JWT_SECRET=
JWT_TTL=1440
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
Expand All @@ -26,38 +29,44 @@ DB_DATABASE_TEST=${DB_DATABASE}_test
DB_USERNAME=laradock
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=your_project_redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_SCHEME=null
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

VITE_APP_NAME="${APP_NAME}"

###########################################################
##########################################################
################ Third Party Integrations #################
###########################################################

Expand All @@ -67,24 +76,15 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
###################### Docker Setup #######################
###########################################################
# To extend the composer process
COMPOSER_PROCESS_TIMEOUT=300

# A fix for Windows users, to ensure the application path works
COMPOSE_CONVERT_WINDOWS_PATHS=0
COMPOSER_PROCESS_TIMEOUT=-1

# Choose storage path on your machine. For all storage systems
DATA_PATH_HOST=./storage/laradock/

### PHP ###########################################

# Select a PHP version of the Workspace and PHP-FPM containers (Does not apply to HHVM).
PHP_VERSION=7.4

# Enable Xdebug
PHP_XDEBUG_ENABLE=false
PHP_XDEBUG_REMOTE_CONNECT_BACK=false
# use this value when PHP_VERSION is above 7.2, ie. 7.3
PHP_XDEBUG_VERSION=-2.7.0
PHP_VERSION=8.4

### NGINX #################################################

Expand Down
14 changes: 10 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
6 changes: 1 addition & 5 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Specialtactics\L5Api\Http\Controllers\RestfulController as BaseController;

class Controller extends BaseController
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
16 changes: 8 additions & 8 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ class Kernel extends HttpKernel
/**
* The application's route middleware groups.
*
* @var array
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
'snake_case',
'throttle:api',
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Specialtactics\L5Api\Http\Middleware\SnakeCaseInputParameterKeys::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

/**
* The application's route middleware.
* The application's middleware aliases.
*
* These middleware may be assigned to groups or used individually.
* Aliases may be used instead of class names to conveniently assign middleware to routes and groups.
*
* @var array
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
Expand Down
80 changes: 32 additions & 48 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

namespace App\Models;

use Hash;
use Illuminate\Auth\Authenticatable;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Auth\MustVerifyEmail;
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\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Notifications\Notifiable;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
use Illuminate\Auth\Authenticatable;

class User extends BaseModel implements
AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract,
JWTSubject
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword, HasFactory, Notifiable;
/** @use HasFactory<\Database\Factories\UserFactory> */
use Authenticatable, Authorizable, CanResetPassword, MustVerifyEmail, HasFactory, Notifiable;

/**
* @var int Auto increments integer key
Expand All @@ -29,12 +31,12 @@ class User extends BaseModel implements
/**
* @var array Relations to load implicitly by Restful controllers
*/
public static $localWith = ['primaryRole', 'roles'];
public static $itemWith = ['primaryRole', 'roles'];

/**
* The attributes that are mass assignable.
*
* @var array
* @var list<string>
*/
protected $fillable = [
'name',
Expand All @@ -44,9 +46,9 @@ class User extends BaseModel implements
];

/**
* The attributes that should be hidden for arrays.
* The attributes that should be hidden for serialization.
*
* @var array
* @var list<string>
*/
protected $hidden = [
'password',
Expand All @@ -55,35 +57,24 @@ class User extends BaseModel implements
];

/**
* The attributes that should be cast to native types.
* Get the attributes that should be cast.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Model's boot function
* @return array<string, string>
*/
public static function boot()
protected function casts(): array
{
parent::boot();

static::saving(function (self $user) {
// Hash user password, if not already hashed
if (Hash::needsRehash($user->password)) {
$user->password = Hash::make($user->password);
}
});
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}

/**
* Return the validation rules for this model
*
* @return array Rules
*/
public function getValidationRules()
public function getValidationRules(): array
{
return [
'email' => 'email|max:255|unique:users',
Expand All @@ -92,30 +83,28 @@ public function getValidationRules()
];
}

/**
* User's primary role
*
* @return \Illuminate\Database\Eloquent\Relations\belongsTo
*/
public function primaryRole()
public static function boot(): void
{
parent::boot();
}

public function primaryRole(): BelongsTo
{
return $this->belongsTo(Role::class, 'primary_role');
}

/**
* User's secondary roles
*
* @return \Illuminate\Database\Eloquent\Relations\belongsToMany
*/
public function roles()
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id');
}

/**
* Get all user's roles
*/
public function getRoles()
public function getRoles(): array
{
$allRoles = array_merge(
[
Expand All @@ -127,12 +116,7 @@ public function getRoles()
return $allRoles;
}

/**
* Is this user an admin?
*
* @return bool
*/
public function isAdmin()
public function isAdmin(): bool
{
return $this->primaryRole->name == Role::ROLE_ADMIN;
}
Expand All @@ -143,7 +127,7 @@ public function isAdmin()
*
* @return mixed
*/
public function getJWTIdentifier()
public function getJWTIdentifier(): string
{
return $this->getKey();
}
Expand All @@ -154,7 +138,7 @@ public function getJWTIdentifier()
*
* @return array
*/
public function getJWTCustomClaims()
public function getJWTCustomClaims(): array
{
return [
'user' => [
Expand All @@ -170,7 +154,7 @@ public function getJWTCustomClaims()
*
* @return string
*/
public function getAuthIdentifierName()
public function getAuthIdentifierName(): string
{
return $this->getKeyName();
}
Expand Down
Loading

0 comments on commit 857e446

Please sign in to comment.