├── public ├── favicon.ico ├── robots.txt ├── img │ ├── login.png │ ├── dashboard.png │ ├── user list.png │ ├── roles list.png │ └── profile setting.png ├── index.php ├── .htaccess └── css │ └── app.css ├── database ├── .gitignore ├── migrations │ ├── 2025_08_04_064724_add_is_active_column_to_users_table.php │ ├── 2025_08_04_064707_create_roles_table.php │ ├── 2025_08_04_064721_create_user_roles_table.php │ ├── 2025_08_04_064724_create_role_permissions_table.php │ ├── 2025_08_04_064717_create_permissions_table.php │ ├── 0001_01_01_000001_create_cache_table.php │ ├── 0001_01_01_000000_create_users_table.php │ ├── 0001_01_01_000002_create_jobs_table.php │ └── 2025_08_04_073354_add_database_indexes_for_optimization.php ├── factories │ └── UserFactory.php └── seeders │ ├── DatabaseSeeder.php │ ├── PermissionSeeder.php │ └── RoleSeeder.php ├── bootstrap ├── cache │ └── .gitignore ├── providers.php └── app.php ├── resources ├── js │ ├── app.js │ └── bootstrap.js ├── sass │ ├── _variables.scss │ └── app.scss ├── views │ ├── roles │ │ └── index.blade.php │ ├── users │ │ └── index.blade.php │ ├── home.blade.php │ ├── auth │ │ ├── verify.blade.php │ │ ├── passwords │ │ │ ├── email.blade.php │ │ │ ├── confirm.blade.php │ │ │ └── reset.blade.php │ │ ├── register.blade.php │ │ └── login.blade.php │ ├── livewire │ │ ├── profile-form.blade.php │ │ ├── password-form.blade.php │ │ ├── users │ │ │ └── user-form.blade.php │ │ ├── roles │ │ │ └── role-form.blade.php │ │ └── settings │ │ │ └── profile-settings.blade.php │ └── profile │ │ └── index.blade.php └── css │ └── app.css ├── storage ├── logs │ └── .gitignore ├── app │ ├── private │ │ └── .gitignore │ ├── public │ │ └── .gitignore │ └── .gitignore └── framework │ ├── testing │ └── .gitignore │ ├── views │ └── .gitignore │ ├── cache │ ├── data │ │ └── .gitignore │ └── .gitignore │ ├── sessions │ └── .gitignore │ └── .gitignore ├── postcss.config.js ├── tests ├── TestCase.php ├── Unit │ └── ExampleTest.php └── Feature │ └── ExampleTest.php ├── .gitattributes ├── routes ├── console.php └── web.php ├── .editorconfig ├── app ├── Http │ └── Controllers │ │ ├── Controller.php │ │ ├── HomeController.php │ │ └── Auth │ │ ├── ForgotPasswordController.php │ │ ├── ResetPasswordController.php │ │ ├── ConfirmPasswordController.php │ │ ├── LoginController.php │ │ ├── VerificationController.php │ │ └── RegisterController.php ├── Domains │ ├── Permission │ │ └── Models │ │ │ └── Permission.php │ ├── User │ │ └── Models │ │ │ └── User.php │ └── Role │ │ └── Models │ │ └── Role.php ├── Shared │ ├── Middleware │ │ ├── CheckRole.php │ │ └── CheckPermission.php │ ├── Traits │ │ ├── HasPermissions.php │ │ ├── WithAlerts.php │ │ └── HasRoles.php │ └── Services │ │ ├── CacheService.php │ │ └── LoggerService.php ├── Livewire │ ├── ProfileForm.php │ ├── PasswordForm.php │ ├── Users │ │ ├── UserForm.php │ │ └── UserList.php │ └── Roles │ │ ├── RoleForm.php │ │ └── RoleList.php └── Providers │ └── AppServiceProvider.php ├── vite.config.js ├── .gitignore ├── artisan ├── package.json ├── tailwind.config.js ├── config ├── services.php ├── filesystems.php ├── cache.php ├── mail.php ├── queue.php ├── auth.php ├── app.php ├── logging.php ├── database.php └── session.php ├── phpunit.xml ├── .env.example ├── composer.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap'; 2 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /storage/app/private/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !private/ 3 | !public/ 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | @endsection -------------------------------------------------------------------------------- /resources/views/users/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 | 6 | 7 |
8 | @endsection -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 8 | })->purpose('Display an inspiring quote'); 9 | -------------------------------------------------------------------------------- /tests/Unit/ExampleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | handleCommand(new ArgvInput); 17 | 18 | exit($status); 19 | -------------------------------------------------------------------------------- /app/Http/Controllers/HomeController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 17 | } 18 | 19 | /** 20 | * Show the application dashboard. 21 | * 22 | * @return \Illuminate\Contracts\Support\Renderable 23 | */ 24 | public function index() 25 | { 26 | return view('home'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/package.json", 3 | "private": true, 4 | "type": "module", 5 | "scripts": { 6 | "build": "vite build", 7 | "dev": "vite" 8 | }, 9 | "devDependencies": { 10 | "@popperjs/core": "^2.11.6", 11 | "@tailwindcss/vite": "^4.0.0", 12 | "autoprefixer": "^10.4.21", 13 | "axios": "^1.8.2", 14 | "bootstrap": "^5.2.3", 15 | "concurrently": "^9.0.1", 16 | "laravel-vite-plugin": "^2.0.0", 17 | "postcss": "^8.5.6", 18 | "sass": "^1.56.1", 19 | "tailwindcss": "^4.1.11", 20 | "vite": "^7.0.4" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Dashboard') }}
9 | 10 |
11 | @if (session('status')) 12 | 15 | @endif 16 | 17 | {{ __('You are logged in!') }} 18 |
19 |
20 |
21 |
22 |
23 | @endsection 24 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: [ 4 | "./resources/**/*.blade.php", 5 | "./resources/**/*.js", 6 | "./resources/**/*.vue", 7 | "./app/**/*.php", 8 | ], 9 | theme: { 10 | extend: { 11 | colors: { 12 | primary: { 13 | 50: '#eff6ff', 14 | 100: '#dbeafe', 15 | 200: '#bfdbfe', 16 | 300: '#93c5fd', 17 | 400: '#60a5fa', 18 | 500: '#3b82f6', 19 | 600: '#2563eb', 20 | 700: '#1d4ed8', 21 | 800: '#1e40af', 22 | 900: '#1e3a8a', 23 | }, 24 | }, 25 | fontFamily: { 26 | sans: ['Inter', 'ui-sans-serif', 'system-ui'], 27 | }, 28 | }, 29 | }, 30 | plugins: [], 31 | } -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withRouting( 9 | web: __DIR__.'/../routes/web.php', 10 | commands: __DIR__.'/../routes/console.php', 11 | health: '/up', 12 | ) 13 | ->withMiddleware(function (Middleware $middleware): void { 14 | $middleware->alias([ 15 | 'permission' => \App\Shared\Middleware\CheckPermission::class, 16 | 'role' => \App\Shared\Middleware\CheckRole::class, 17 | ]); 18 | }) 19 | ->withExceptions(function (Exceptions $exceptions): void { 20 | // 21 | })->create(); 22 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | boolean('is_active')->default(true)->after('email_verified_at'); 16 | }); 17 | } 18 | 19 | /** 20 | * Reverse the migrations. 21 | */ 22 | public function down(): void 23 | { 24 | Schema::table('users', function (Blueprint $table) { 25 | $table->dropColumn('is_active'); 26 | }); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /app/Domains/Permission/Models/Permission.php: -------------------------------------------------------------------------------- 1 | 'boolean', 26 | ]; 27 | } 28 | 29 | public function roles(): BelongsToMany 30 | { 31 | return $this->belongsToMany(Role::class, 'role_permissions'); 32 | } 33 | } -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Handle X-XSRF-Token Header 13 | RewriteCond %{HTTP:x-xsrf-token} . 14 | RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}] 15 | 16 | # Redirect Trailing Slashes If Not A Folder... 17 | RewriteCond %{REQUEST_FILENAME} !-d 18 | RewriteCond %{REQUEST_URI} (.+)/$ 19 | RewriteRule ^ %1 [L,R=301] 20 | 21 | # Send Requests To Front Controller... 22 | RewriteCond %{REQUEST_FILENAME} !-d 23 | RewriteCond %{REQUEST_FILENAME} !-f 24 | RewriteRule ^ index.php [L] 25 | 26 | -------------------------------------------------------------------------------- /app/Shared/Middleware/CheckRole.php: -------------------------------------------------------------------------------- 1 | check()) { 19 | return redirect()->route('login'); 20 | } 21 | 22 | $user = auth()->user(); 23 | 24 | if (!$user->hasAnyRole($roles)) { 25 | abort(403, 'You do not have the required role to access this resource.'); 26 | } 27 | 28 | return $next($request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /database/migrations/2025_08_04_064707_create_roles_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name')->unique(); 17 | $table->string('display_name'); 18 | $table->text('description')->nullable(); 19 | $table->boolean('is_active')->default(true); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::dropIfExists('roles'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /database/migrations/2025_08_04_064721_create_user_roles_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('user_id')->constrained()->onDelete('cascade'); 17 | $table->foreignId('role_id')->constrained()->onDelete('cascade'); 18 | $table->timestamps(); 19 | 20 | $table->unique(['user_id', 'role_id']); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::dropIfExists('user_roles'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | check()) { 19 | return redirect()->route('login'); 20 | } 21 | 22 | $user = auth()->user(); 23 | 24 | foreach ($permissions as $permission) { 25 | if (!$user->hasPermission($permission)) { 26 | abort(403, 'You do not have permission to access this resource.'); 27 | } 28 | } 29 | 30 | return $next($request); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2025_08_04_064724_create_role_permissions_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->foreignId('role_id')->constrained()->onDelete('cascade'); 17 | $table->foreignId('permission_id')->constrained()->onDelete('cascade'); 18 | $table->timestamps(); 19 | 20 | $table->unique(['role_id', 'permission_id']); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::dropIfExists('role_permissions'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /database/migrations/2025_08_04_064717_create_permissions_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name')->unique(); 17 | $table->string('display_name'); 18 | $table->text('description')->nullable(); 19 | $table->string('group')->nullable(); 20 | $table->boolean('is_active')->default(true); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('permissions'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000001_create_cache_table.php: -------------------------------------------------------------------------------- 1 | string('key')->primary(); 16 | $table->mediumText('value'); 17 | $table->integer('expiration'); 18 | }); 19 | 20 | Schema::create('cache_locks', function (Blueprint $table) { 21 | $table->string('key')->primary(); 22 | $table->string('owner'); 23 | $table->integer('expiration'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('cache'); 33 | Schema::dropIfExists('cache_locks'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /app/Domains/User/Models/User.php: -------------------------------------------------------------------------------- 1 | 'datetime', 36 | 'password' => 'hashed', 37 | 'is_active' => 'boolean', 38 | ]; 39 | } 40 | } -------------------------------------------------------------------------------- /app/Livewire/ProfileForm.php: -------------------------------------------------------------------------------- 1 | name = $user->name ?? ''; 20 | $this->email = $user->email ?? ''; 21 | } 22 | 23 | public function updateProfile() 24 | { 25 | $this->validate([ 26 | 'name' => 'required|string|max:255', 27 | 'email' => 'required|email|max:255|unique:users,email,' . Auth::id(), 28 | ]); 29 | 30 | $user = Auth::user(); 31 | 32 | $user->update([ 33 | 'name' => $this->name, 34 | 'email' => $this->email, 35 | ]); 36 | 37 | $this->showSuccessToast('Profile updated successfully!'); 38 | $this->dispatch('$refresh'); 39 | } 40 | 41 | public function render() 42 | { 43 | return view('livewire.profile-form'); 44 | } 45 | } -------------------------------------------------------------------------------- /app/Domains/Role/Models/Role.php: -------------------------------------------------------------------------------- 1 | 'boolean', 26 | ]; 27 | } 28 | 29 | public function users(): BelongsToMany 30 | { 31 | return $this->belongsToMany(User::class, 'user_roles'); 32 | } 33 | 34 | public function permissions(): BelongsToMany 35 | { 36 | return $this->belongsToMany(Permission::class, 'role_permissions'); 37 | } 38 | 39 | public function hasPermission(string $permission): bool 40 | { 41 | return $this->permissions()->where('name', $permission)->exists(); 42 | } 43 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ConfirmPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/LoginController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 38 | $this->middleware('auth')->only('logout'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'token' => env('POSTMARK_TOKEN'), 19 | ], 20 | 21 | 'resend' => [ 22 | 'key' => env('RESEND_KEY'), 23 | ], 24 | 25 | 'ses' => [ 26 | 'key' => env('AWS_ACCESS_KEY_ID'), 27 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 28 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 29 | ], 30 | 31 | 'slack' => [ 32 | 'notifications' => [ 33 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 34 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 35 | ], 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /resources/views/auth/verify.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Verify Your Email Address') }}
9 | 10 |
11 | @if (session('resent')) 12 | 15 | @endif 16 | 17 | {{ __('Before proceeding, please check your email for a verification link.') }} 18 | {{ __('If you did not receive the email') }}, 19 |
20 | @csrf 21 | . 22 |
23 |
24 |
25 |
26 |
27 |
28 | @endsection 29 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerificationController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 38 | $this->middleware('signed')->only('verify'); 39 | $this->middleware('throttle:6,1')->only('verify', 'resend'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | check()) { 8 | return redirect()->route('dashboard'); 9 | } 10 | return redirect()->route('login'); 11 | }); 12 | 13 | // Dashboard Route (redirect /home to /dashboard) 14 | Route::get('/dashboard', function () { 15 | return view('dashboard'); 16 | })->middleware(['auth'])->name('dashboard'); 17 | 18 | // User Management Routes 19 | Route::middleware(['auth', 'permission:users.view'])->group(function () { 20 | Route::get('/users', function () { 21 | return view('users.index'); 22 | })->name('users.index'); 23 | }); 24 | 25 | // Role Management Routes 26 | Route::middleware(['auth', 'permission:roles.view'])->group(function () { 27 | Route::get('/roles', function () { 28 | return view('roles.index'); 29 | })->name('roles.index'); 30 | }); 31 | 32 | // Profile Settings Routes 33 | Route::middleware(['auth'])->group(function () { 34 | Route::get('/profile', function () { 35 | return view('profile.index'); 36 | })->name('profile.index'); 37 | }); 38 | 39 | Auth::routes(); 40 | 41 | Route::get('/home', function () { 42 | return redirect()->route('dashboard'); 43 | })->middleware(['auth'])->name('home'); 44 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | check() && auth()->user()->hasPermission($permission); 26 | }); 27 | 28 | // Blade directive for role checks 29 | Blade::if('role', function ($role) { 30 | return auth()->check() && auth()->user()->hasRole($role); 31 | }); 32 | 33 | // Blade directive for any role check 34 | Blade::if('anyrole', function (...$roles) { 35 | return auth()->check() && auth()->user()->hasAnyRole($roles); 36 | }); 37 | 38 | // Blade directive for all roles check 39 | Blade::if('allroles', function (...$roles) { 40 | return auth()->check() && auth()->user()->hasAllRoles($roles); 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | tests/Unit 10 | 11 | 12 | tests/Feature 13 | 14 | 15 | 16 | 17 | app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | APP_LOCALE=en 8 | APP_FALLBACK_LOCALE=en 9 | APP_FAKER_LOCALE=en_US 10 | 11 | APP_MAINTENANCE_DRIVER=file 12 | # APP_MAINTENANCE_STORE=database 13 | 14 | PHP_CLI_SERVER_WORKERS=4 15 | 16 | BCRYPT_ROUNDS=12 17 | 18 | LOG_CHANNEL=stack 19 | LOG_STACK=single 20 | LOG_DEPRECATIONS_CHANNEL=null 21 | LOG_LEVEL=debug 22 | 23 | DB_CONNECTION=sqlite 24 | # DB_HOST=127.0.0.1 25 | # DB_PORT=3306 26 | # DB_DATABASE=laravel 27 | # DB_USERNAME=root 28 | # DB_PASSWORD= 29 | 30 | SESSION_DRIVER=database 31 | SESSION_LIFETIME=120 32 | SESSION_ENCRYPT=false 33 | SESSION_PATH=/ 34 | SESSION_DOMAIN=null 35 | 36 | BROADCAST_CONNECTION=log 37 | FILESYSTEM_DISK=local 38 | QUEUE_CONNECTION=database 39 | 40 | CACHE_STORE=database 41 | # CACHE_PREFIX= 42 | 43 | MEMCACHED_HOST=127.0.0.1 44 | 45 | REDIS_CLIENT=phpredis 46 | REDIS_HOST=127.0.0.1 47 | REDIS_PASSWORD=null 48 | REDIS_PORT=6379 49 | 50 | MAIL_MAILER=log 51 | MAIL_SCHEME=null 52 | MAIL_HOST=127.0.0.1 53 | MAIL_PORT=2525 54 | MAIL_USERNAME=null 55 | MAIL_PASSWORD=null 56 | MAIL_FROM_ADDRESS="hello@example.com" 57 | MAIL_FROM_NAME="${APP_NAME}" 58 | 59 | AWS_ACCESS_KEY_ID= 60 | AWS_SECRET_ACCESS_KEY= 61 | AWS_DEFAULT_REGION=us-east-1 62 | AWS_BUCKET= 63 | AWS_USE_PATH_STYLE_ENDPOINT=false 64 | 65 | VITE_APP_NAME="${APP_NAME}" 66 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | import 'bootstrap'; 2 | 3 | /** 4 | * We'll load the axios HTTP library which allows us to easily issue requests 5 | * to our Laravel back-end. This library automatically handles sending the 6 | * CSRF token as a header based on the value of the "XSRF" token cookie. 7 | */ 8 | 9 | import axios from 'axios'; 10 | window.axios = axios; 11 | 12 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 13 | 14 | /** 15 | * Echo exposes an expressive API for subscribing to channels and listening 16 | * for events that are broadcast by Laravel. Echo and event broadcasting 17 | * allows your team to easily build robust real-time web applications. 18 | */ 19 | 20 | // import Echo from 'laravel-echo'; 21 | 22 | // import Pusher from 'pusher-js'; 23 | // window.Pusher = Pusher; 24 | 25 | // window.Echo = new Echo({ 26 | // broadcaster: 'pusher', 27 | // key: import.meta.env.VITE_PUSHER_APP_KEY, 28 | // cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1', 29 | // wsHost: import.meta.env.VITE_PUSHER_HOST ?? `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`, 30 | // wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80, 31 | // wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443, 32 | // forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https', 33 | // enabledTransports: ['ws', 'wss'], 34 | // }); 35 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | @import 'tailwindcss/base'; 2 | @import 'tailwindcss/components'; 3 | @import 'tailwindcss/utilities'; 4 | 5 | @layer base { 6 | html { 7 | font-family: 'Inter', ui-sans-serif, system-ui, sans-serif; 8 | } 9 | } 10 | 11 | @layer components { 12 | .btn { 13 | @apply px-4 py-2 rounded-lg font-medium transition-colors duration-200; 14 | } 15 | 16 | .btn-primary { 17 | @apply bg-primary-600 hover:bg-primary-700 text-white; 18 | } 19 | 20 | .btn-secondary { 21 | @apply bg-gray-200 hover:bg-gray-300 text-gray-800; 22 | } 23 | 24 | .btn-danger { 25 | @apply bg-red-600 hover:bg-red-700 text-white; 26 | } 27 | 28 | .form-input { 29 | @apply w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent; 30 | } 31 | 32 | .form-label { 33 | @apply block text-sm font-medium text-gray-700 mb-1; 34 | } 35 | 36 | .card { 37 | @apply bg-white rounded-lg shadow-md border border-gray-200; 38 | } 39 | 40 | .table-auto { 41 | @apply w-full border-collapse; 42 | } 43 | 44 | .table-auto th { 45 | @apply px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200; 46 | } 47 | 48 | .table-auto td { 49 | @apply px-4 py-4 whitespace-nowrap text-sm text-gray-900 border-b border-gray-200; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * The name of the factory's corresponding model. 16 | * 17 | * @var class-string<\Illuminate\Database\Eloquent\Model> 18 | */ 19 | protected $model = \App\Domains\User\Models\User::class; 20 | 21 | /** 22 | * The current password being used by the factory. 23 | */ 24 | protected static ?string $password; 25 | 26 | /** 27 | * Define the model's default state. 28 | * 29 | * @return array 30 | */ 31 | public function definition(): array 32 | { 33 | return [ 34 | 'name' => fake()->name(), 35 | 'email' => fake()->unique()->safeEmail(), 36 | 'email_verified_at' => now(), 37 | 'password' => static::$password ??= Hash::make('password'), 38 | 'remember_token' => Str::random(10), 39 | 'is_active' => true, 40 | ]; 41 | } 42 | 43 | /** 44 | * Indicate that the model's email address should be unverified. 45 | */ 46 | public function unverified(): static 47 | { 48 | return $this->state(fn (array $attributes) => [ 49 | 'email_verified_at' => null, 50 | ]); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/Shared/Traits/HasPermissions.php: -------------------------------------------------------------------------------- 1 | roles()->whereHas('permissions', function ($query) use ($permission) { 10 | $query->where('permissions.name', $permission)->where('permissions.is_active', true); 11 | })->exists(); 12 | } 13 | 14 | public function hasAnyPermission(array $permissions): bool 15 | { 16 | return $this->roles()->whereHas('permissions', function ($query) use ($permissions) { 17 | $query->whereIn('permissions.name', $permissions)->where('permissions.is_active', true); 18 | })->exists(); 19 | } 20 | 21 | public function hasAllPermissions(array $permissions): bool 22 | { 23 | foreach ($permissions as $permission) { 24 | if (!$this->hasPermission($permission)) { 25 | return false; 26 | } 27 | } 28 | 29 | return true; 30 | } 31 | 32 | public function getPermissions(): array 33 | { 34 | return $this->roles() 35 | ->with('permissions') 36 | ->get() 37 | ->pluck('permissions') 38 | ->flatten() 39 | ->where('is_active', true) 40 | ->pluck('name') 41 | ->unique() 42 | ->values() 43 | ->toArray(); 44 | } 45 | 46 | public function canAccessResource(string $resource, string $action): bool 47 | { 48 | $permission = "{$resource}.{$action}"; 49 | return $this->hasPermission($permission); 50 | } 51 | } -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call([ 17 | PermissionSeeder::class, 18 | RoleSeeder::class, 19 | ]); 20 | 21 | // Create a super admin user manually 22 | $superAdmin = User::create([ 23 | 'name' => 'Super Admin', 24 | 'email' => 'admin@example.com', 25 | 'password' => bcrypt('password'), 26 | 'is_active' => true, 27 | 'email_verified_at' => now(), 28 | ]); 29 | 30 | // Assign super admin role 31 | $superAdminRole = \App\Domains\Role\Models\Role::where('name', 'super-admin')->first(); 32 | if ($superAdminRole) { 33 | $superAdmin->roles()->attach($superAdminRole->id); 34 | } 35 | 36 | // Create a test user manually 37 | $testUser = User::create([ 38 | 'name' => 'Test User', 39 | 'email' => 'user@example.com', 40 | 'password' => bcrypt('password'), 41 | 'is_active' => true, 42 | 'email_verified_at' => now(), 43 | ]); 44 | 45 | // Assign user role 46 | $userRole = \App\Domains\Role\Models\Role::where('name', 'user')->first(); 47 | if ($userRole) { 48 | $testUser->roles()->attach($userRole->id); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name'); 17 | $table->string('email')->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | 24 | Schema::create('password_reset_tokens', function (Blueprint $table) { 25 | $table->string('email')->primary(); 26 | $table->string('token'); 27 | $table->timestamp('created_at')->nullable(); 28 | }); 29 | 30 | Schema::create('sessions', function (Blueprint $table) { 31 | $table->string('id')->primary(); 32 | $table->foreignId('user_id')->nullable()->index(); 33 | $table->string('ip_address', 45)->nullable(); 34 | $table->text('user_agent')->nullable(); 35 | $table->longText('payload'); 36 | $table->integer('last_activity')->index(); 37 | }); 38 | } 39 | 40 | /** 41 | * Reverse the migrations. 42 | */ 43 | public function down(): void 44 | { 45 | Schema::dropIfExists('users'); 46 | Schema::dropIfExists('password_reset_tokens'); 47 | Schema::dropIfExists('sessions'); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /public/css/app.css: -------------------------------------------------------------------------------- 1 | /* Basic Tailwind CSS - compiled version */ 2 | @import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css'); 3 | 4 | /* SweetAlert2 for modern alerts */ 5 | @import url('https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css'); 6 | 7 | /* Additional custom styles */ 8 | .table-responsive { 9 | overflow-x: auto; 10 | } 11 | 12 | .btn-primary { 13 | background-color: #3b82f6; 14 | color: white; 15 | padding: 0.5rem 1rem; 16 | border-radius: 0.375rem; 17 | border: none; 18 | cursor: pointer; 19 | } 20 | 21 | .btn-primary:hover { 22 | background-color: #2563eb; 23 | } 24 | 25 | .btn-secondary { 26 | background-color: #6b7280; 27 | color: white; 28 | padding: 0.5rem 1rem; 29 | border-radius: 0.375rem; 30 | border: none; 31 | cursor: pointer; 32 | } 33 | 34 | .btn-secondary:hover { 35 | background-color: #4b5563; 36 | } 37 | 38 | .form-control { 39 | width: 100%; 40 | padding: 0.5rem 0.75rem; 41 | border: 1px solid #d1d5db; 42 | border-radius: 0.375rem; 43 | margin-bottom: 0.5rem; 44 | } 45 | 46 | .form-control:focus { 47 | outline: none; 48 | border-color: #3b82f6; 49 | box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); 50 | } 51 | 52 | .alert { 53 | padding: 0.75rem 1rem; 54 | margin-bottom: 1rem; 55 | border-radius: 0.375rem; 56 | } 57 | 58 | .alert-success { 59 | background-color: #d1fae5; 60 | border: 1px solid #a7f3d0; 61 | color: #065f46; 62 | } 63 | 64 | .modal { 65 | position: fixed; 66 | top: 0; 67 | left: 0; 68 | width: 100%; 69 | height: 100%; 70 | background-color: rgba(0, 0, 0, 0.5); 71 | display: flex; 72 | justify-content: center; 73 | align-items: center; 74 | z-index: 1000; 75 | } 76 | 77 | .modal-content { 78 | background: white; 79 | padding: 2rem; 80 | border-radius: 0.5rem; 81 | max-width: 500px; 82 | width: 90%; 83 | max-height: 90%; 84 | overflow-y: auto; 85 | } -------------------------------------------------------------------------------- /app/Shared/Traits/WithAlerts.php: -------------------------------------------------------------------------------- 1 | dispatch('show-alert', [ 10 | 'type' => $type, 11 | 'title' => $title, 12 | 'text' => $text, 13 | 'options' => $options, 14 | ]); 15 | } 16 | 17 | public function showToast($type, $title) 18 | { 19 | $this->dispatch('show-toast', [ 20 | 'type' => $type, 21 | 'title' => $title, 22 | ]); 23 | } 24 | 25 | public function showConfirm($title, $text, $method, $params = [], $confirmText = 'Yes, proceed!', $cancelText = 'Cancel') 26 | { 27 | $this->dispatch('show-confirm', [ 28 | 'title' => $title, 29 | 'text' => $text, 30 | 'method' => $method, 31 | 'params' => $params, 32 | 'confirmText' => $confirmText, 33 | 'cancelText' => $cancelText, 34 | ]); 35 | } 36 | 37 | public function showSuccess($title, $text = '') 38 | { 39 | $this->showAlert('success', $title, $text); 40 | } 41 | 42 | public function showError($title, $text = '') 43 | { 44 | $this->showAlert('error', $title, $text); 45 | } 46 | 47 | public function showWarning($title, $text = '') 48 | { 49 | $this->showAlert('warning', $title, $text); 50 | } 51 | 52 | public function showInfo($title, $text = '') 53 | { 54 | $this->showAlert('info', $title, $text); 55 | } 56 | 57 | public function showSuccessToast($title) 58 | { 59 | $this->showToast('success', $title); 60 | } 61 | 62 | public function showErrorToast($title) 63 | { 64 | $this->showToast('error', $title); 65 | } 66 | 67 | public function showWarningToast($title) 68 | { 69 | $this->showToast('warning', $title); 70 | } 71 | 72 | public function showInfoToast($title) 73 | { 74 | $this->showToast('info', $title); 75 | } 76 | } -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000002_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('queue')->index(); 17 | $table->longText('payload'); 18 | $table->unsignedTinyInteger('attempts'); 19 | $table->unsignedInteger('reserved_at')->nullable(); 20 | $table->unsignedInteger('available_at'); 21 | $table->unsignedInteger('created_at'); 22 | }); 23 | 24 | Schema::create('job_batches', function (Blueprint $table) { 25 | $table->string('id')->primary(); 26 | $table->string('name'); 27 | $table->integer('total_jobs'); 28 | $table->integer('pending_jobs'); 29 | $table->integer('failed_jobs'); 30 | $table->longText('failed_job_ids'); 31 | $table->mediumText('options')->nullable(); 32 | $table->integer('cancelled_at')->nullable(); 33 | $table->integer('created_at'); 34 | $table->integer('finished_at')->nullable(); 35 | }); 36 | 37 | Schema::create('failed_jobs', function (Blueprint $table) { 38 | $table->id(); 39 | $table->string('uuid')->unique(); 40 | $table->text('connection'); 41 | $table->text('queue'); 42 | $table->longText('payload'); 43 | $table->longText('exception'); 44 | $table->timestamp('failed_at')->useCurrent(); 45 | }); 46 | } 47 | 48 | /** 49 | * Reverse the migrations. 50 | */ 51 | public function down(): void 52 | { 53 | Schema::dropIfExists('jobs'); 54 | Schema::dropIfExists('job_batches'); 55 | Schema::dropIfExists('failed_jobs'); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/email.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Reset Password') }}
9 | 10 |
11 | @if (session('status')) 12 | 15 | @endif 16 | 17 |
18 | @csrf 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | @error('email') 27 | 28 | {{ $message }} 29 | 30 | @enderror 31 |
32 |
33 | 34 |
35 |
36 | 39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | @endsection 48 | -------------------------------------------------------------------------------- /app/Shared/Traits/HasRoles.php: -------------------------------------------------------------------------------- 1 | belongsToMany(Role::class, 'user_roles'); 13 | } 14 | 15 | public function hasRole($role): bool 16 | { 17 | if (is_string($role)) { 18 | return $this->roles()->where('roles.name', $role)->exists(); 19 | } 20 | 21 | if (is_array($role)) { 22 | return $this->roles()->whereIn('roles.name', $role)->exists(); 23 | } 24 | 25 | return $this->roles()->where('roles.id', $role->id)->exists(); 26 | } 27 | 28 | public function hasAnyRole(array $roles): bool 29 | { 30 | return $this->roles()->whereIn('roles.name', $roles)->exists(); 31 | } 32 | 33 | public function hasAllRoles(array $roles): bool 34 | { 35 | return $this->roles()->whereIn('roles.name', $roles)->count() === count($roles); 36 | } 37 | 38 | public function assignRole($role): self 39 | { 40 | if (is_string($role)) { 41 | $role = Role::where('name', $role)->first(); 42 | } 43 | 44 | if ($role) { 45 | // Check if role is already assigned 46 | $existingRole = $this->roles()->where('role_id', $role->id)->first(); 47 | if (!$existingRole) { 48 | $this->roles()->attach($role->id); 49 | } 50 | } 51 | 52 | return $this; 53 | } 54 | 55 | public function removeRole($role): self 56 | { 57 | if (is_string($role)) { 58 | $role = Role::where('name', $role)->first(); 59 | } 60 | 61 | if ($role) { 62 | $this->roles()->detach($role->id); 63 | } 64 | 65 | return $this; 66 | } 67 | 68 | public function syncRoles(array $roles): self 69 | { 70 | $roleIds = Role::whereIn('name', $roles)->pluck('id')->toArray(); 71 | $this->roles()->sync($roleIds); 72 | 73 | return $this; 74 | } 75 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 41 | } 42 | 43 | /** 44 | * Get a validator for an incoming registration request. 45 | * 46 | * @param array $data 47 | * @return \Illuminate\Contracts\Validation\Validator 48 | */ 49 | protected function validator(array $data) 50 | { 51 | return Validator::make($data, [ 52 | 'name' => ['required', 'string', 'max:255'], 53 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 54 | 'password' => ['required', 'string', 'min:8', 'confirmed'], 55 | ]); 56 | } 57 | 58 | /** 59 | * Create a new user instance after a valid registration. 60 | * 61 | * @param array $data 62 | * @return \App\Models\User 63 | */ 64 | protected function create(array $data) 65 | { 66 | return User::create([ 67 | 'name' => $data['name'], 68 | 'email' => $data['email'], 69 | 'password' => Hash::make($data['password']), 70 | ]); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/confirm.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Confirm Password') }}
9 | 10 |
11 | {{ __('Please confirm your password before continuing.') }} 12 | 13 |
14 | @csrf 15 | 16 |
17 | 18 | 19 |
20 | 21 | 22 | @error('password') 23 | 24 | {{ $message }} 25 | 26 | @enderror 27 |
28 |
29 | 30 |
31 |
32 | 35 | 36 | @if (Route::has('password.request')) 37 | 38 | {{ __('Forgot Your Password?') }} 39 | 40 | @endif 41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | @endsection 50 | -------------------------------------------------------------------------------- /database/seeders/PermissionSeeder.php: -------------------------------------------------------------------------------- 1 | 'users.view', 'display_name' => 'View Users', 'description' => 'Can view user list and details', 'group' => 'users'], 19 | ['name' => 'users.create', 'display_name' => 'Create Users', 'description' => 'Can create new users', 'group' => 'users'], 20 | ['name' => 'users.edit', 'display_name' => 'Edit Users', 'description' => 'Can edit existing users', 'group' => 'users'], 21 | ['name' => 'users.delete', 'display_name' => 'Delete Users', 'description' => 'Can delete users', 'group' => 'users'], 22 | 23 | // Role permissions 24 | ['name' => 'roles.view', 'display_name' => 'View Roles', 'description' => 'Can view role list and details', 'group' => 'roles'], 25 | ['name' => 'roles.create', 'display_name' => 'Create Roles', 'description' => 'Can create new roles', 'group' => 'roles'], 26 | ['name' => 'roles.edit', 'display_name' => 'Edit Roles', 'description' => 'Can edit existing roles', 'group' => 'roles'], 27 | ['name' => 'roles.delete', 'display_name' => 'Delete Roles', 'description' => 'Can delete roles', 'group' => 'roles'], 28 | 29 | // Permission permissions 30 | ['name' => 'permissions.view', 'display_name' => 'View Permissions', 'description' => 'Can view permission list', 'group' => 'permissions'], 31 | ['name' => 'permissions.manage', 'display_name' => 'Manage Permissions', 'description' => 'Can assign/remove permissions from roles', 'group' => 'permissions'], 32 | 33 | // System permissions 34 | ['name' => 'system.settings', 'display_name' => 'System Settings', 'description' => 'Can access system settings', 'group' => 'system'], 35 | ['name' => 'system.logs', 'display_name' => 'View Logs', 'description' => 'Can view system logs', 'group' => 'system'], 36 | ]; 37 | 38 | foreach ($permissions as $permission) { 39 | Permission::firstOrCreate( 40 | ['name' => $permission['name']], 41 | $permission 42 | ); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /database/seeders/RoleSeeder.php: -------------------------------------------------------------------------------- 1 | 'super-admin'], 20 | [ 21 | 'display_name' => 'Super Administrator', 22 | 'description' => 'Has access to all system functions', 23 | 'is_active' => true, 24 | ] 25 | ); 26 | 27 | // Assign all permissions to super admin 28 | $allPermissions = Permission::all(); 29 | $superAdmin->permissions()->sync($allPermissions->pluck('id')); 30 | 31 | // Create Admin role 32 | $admin = Role::firstOrCreate( 33 | ['name' => 'admin'], 34 | [ 35 | 'display_name' => 'Administrator', 36 | 'description' => 'Administrative access to most system functions', 37 | 'is_active' => true, 38 | ] 39 | ); 40 | 41 | // Assign admin permissions (all except system settings) 42 | $adminPermissions = Permission::whereNotIn('name', ['system.settings'])->get(); 43 | $admin->permissions()->sync($adminPermissions->pluck('id')); 44 | 45 | // Create Manager role 46 | $manager = Role::firstOrCreate( 47 | ['name' => 'manager'], 48 | [ 49 | 'display_name' => 'Manager', 50 | 'description' => 'Can manage users and view reports', 51 | 'is_active' => true, 52 | ] 53 | ); 54 | 55 | // Assign manager permissions 56 | $managerPermissions = Permission::whereIn('name', [ 57 | 'users.view', 'users.create', 'users.edit', 58 | 'roles.view', 'permissions.view' 59 | ])->get(); 60 | $manager->permissions()->sync($managerPermissions->pluck('id')); 61 | 62 | // Create User role 63 | $user = Role::firstOrCreate( 64 | ['name' => 'user'], 65 | [ 66 | 'display_name' => 'User', 67 | 'description' => 'Basic user access', 68 | 'is_active' => true, 69 | ] 70 | ); 71 | 72 | // Users get no additional permissions by default 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Below you may configure as many filesystem disks as necessary, and you 24 | | may even configure multiple disks for the same driver. Examples for 25 | | most supported storage drivers are configured here for reference. 26 | | 27 | | Supported drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app/private'), 36 | 'serve' => true, 37 | 'throw' => false, 38 | 'report' => false, 39 | ], 40 | 41 | 'public' => [ 42 | 'driver' => 'local', 43 | 'root' => storage_path('app/public'), 44 | 'url' => env('APP_URL').'/storage', 45 | 'visibility' => 'public', 46 | 'throw' => false, 47 | 'report' => false, 48 | ], 49 | 50 | 's3' => [ 51 | 'driver' => 's3', 52 | 'key' => env('AWS_ACCESS_KEY_ID'), 53 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 54 | 'region' => env('AWS_DEFAULT_REGION'), 55 | 'bucket' => env('AWS_BUCKET'), 56 | 'url' => env('AWS_URL'), 57 | 'endpoint' => env('AWS_ENDPOINT'), 58 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 59 | 'throw' => false, 60 | 'report' => false, 61 | ], 62 | 63 | ], 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Symbolic Links 68 | |-------------------------------------------------------------------------- 69 | | 70 | | Here you may configure the symbolic links that will be created when the 71 | | `storage:link` Artisan command is executed. The array keys should be 72 | | the locations of the links and the values should be their targets. 73 | | 74 | */ 75 | 76 | 'links' => [ 77 | public_path('storage') => storage_path('app/public'), 78 | ], 79 | 80 | ]; 81 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://getcomposer.org/schema.json", 3 | "name": "laravel/laravel", 4 | "type": "project", 5 | "description": "The skeleton application for the Laravel framework.", 6 | "keywords": ["laravel", "framework"], 7 | "license": "MIT", 8 | "require": { 9 | "php": "^8.2", 10 | "laravel/framework": "^12.0", 11 | "laravel/tinker": "^2.10.1", 12 | "laravel/ui": "^4.6", 13 | "livewire/livewire": "^3.6", 14 | "monolog/monolog": "^3.9", 15 | "predis/predis": "^3.1" 16 | }, 17 | "require-dev": { 18 | "fakerphp/faker": "^1.23", 19 | "laravel/pail": "^1.2.2", 20 | "laravel/pint": "^1.13", 21 | "laravel/sail": "^1.41", 22 | "mockery/mockery": "^1.6", 23 | "nunomaduro/collision": "^8.6", 24 | "phpunit/phpunit": "^11.5.3" 25 | }, 26 | "autoload": { 27 | "psr-4": { 28 | "App\\": "app/", 29 | "Database\\Factories\\": "database/factories/", 30 | "Database\\Seeders\\": "database/seeders/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Tests\\": "tests/" 36 | } 37 | }, 38 | "scripts": { 39 | "post-autoload-dump": [ 40 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 41 | "@php artisan package:discover --ansi" 42 | ], 43 | "post-update-cmd": [ 44 | "@php artisan vendor:publish --tag=laravel-assets --ansi --force" 45 | ], 46 | "post-root-package-install": [ 47 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 48 | ], 49 | "post-create-project-cmd": [ 50 | "@php artisan key:generate --ansi", 51 | "@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"", 52 | "@php artisan migrate --graceful --ansi" 53 | ], 54 | "dev": [ 55 | "Composer\\Config::disableProcessTimeout", 56 | "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite" 57 | ], 58 | "test": [ 59 | "@php artisan config:clear --ansi", 60 | "@php artisan test" 61 | ] 62 | }, 63 | "extra": { 64 | "laravel": { 65 | "dont-discover": [] 66 | } 67 | }, 68 | "config": { 69 | "optimize-autoloader": true, 70 | "preferred-install": "dist", 71 | "sort-packages": true, 72 | "allow-plugins": { 73 | "pestphp/pest-plugin": true, 74 | "php-http/discovery": true 75 | } 76 | }, 77 | "minimum-stability": "stable", 78 | "prefer-stable": true 79 | } 80 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/reset.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Reset Password') }}
9 | 10 |
11 |
12 | @csrf 13 | 14 | 15 | 16 |
17 | 18 | 19 |
20 | 21 | 22 | @error('email') 23 | 24 | {{ $message }} 25 | 26 | @enderror 27 |
28 |
29 | 30 |
31 | 32 | 33 |
34 | 35 | 36 | @error('password') 37 | 38 | {{ $message }} 39 | 40 | @enderror 41 |
42 |
43 | 44 |
45 | 46 | 47 |
48 | 49 |
50 |
51 | 52 |
53 |
54 | 57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | @endsection 66 | -------------------------------------------------------------------------------- /database/migrations/2025_08_04_073354_add_database_indexes_for_optimization.php: -------------------------------------------------------------------------------- 1 | index(['email', 'is_active']); 17 | $table->index('is_active'); 18 | $table->index('created_at'); 19 | }); 20 | 21 | // Add indexes for roles table 22 | Schema::table('roles', function (Blueprint $table) { 23 | $table->index('is_active'); 24 | $table->index(['name', 'is_active']); 25 | $table->index('created_at'); 26 | }); 27 | 28 | // Add indexes for permissions table 29 | Schema::table('permissions', function (Blueprint $table) { 30 | $table->index('is_active'); 31 | $table->index(['group', 'is_active']); 32 | $table->index(['name', 'is_active']); 33 | $table->index('created_at'); 34 | }); 35 | 36 | // Add indexes for pivot tables for better relationship queries 37 | Schema::table('user_roles', function (Blueprint $table) { 38 | $table->index('user_id'); 39 | $table->index('role_id'); 40 | $table->index(['user_id', 'role_id']); 41 | }); 42 | 43 | Schema::table('role_permissions', function (Blueprint $table) { 44 | $table->index('role_id'); 45 | $table->index('permission_id'); 46 | $table->index(['role_id', 'permission_id']); 47 | }); 48 | } 49 | 50 | /** 51 | * Reverse the migrations. 52 | */ 53 | public function down(): void 54 | { 55 | // Remove indexes for users table 56 | Schema::table('users', function (Blueprint $table) { 57 | $table->dropIndex(['email', 'is_active']); 58 | $table->dropIndex(['is_active']); 59 | $table->dropIndex(['created_at']); 60 | }); 61 | 62 | // Remove indexes for roles table 63 | Schema::table('roles', function (Blueprint $table) { 64 | $table->dropIndex(['is_active']); 65 | $table->dropIndex(['name', 'is_active']); 66 | $table->dropIndex(['created_at']); 67 | }); 68 | 69 | // Remove indexes for permissions table 70 | Schema::table('permissions', function (Blueprint $table) { 71 | $table->dropIndex(['is_active']); 72 | $table->dropIndex(['group', 'is_active']); 73 | $table->dropIndex(['name', 'is_active']); 74 | $table->dropIndex(['created_at']); 75 | }); 76 | 77 | // Remove indexes for pivot tables 78 | Schema::table('user_roles', function (Blueprint $table) { 79 | $table->dropIndex(['user_id']); 80 | $table->dropIndex(['role_id']); 81 | $table->dropIndex(['user_id', 'role_id']); 82 | }); 83 | 84 | Schema::table('role_permissions', function (Blueprint $table) { 85 | $table->dropIndex(['role_id']); 86 | $table->dropIndex(['permission_id']); 87 | $table->dropIndex(['role_id', 'permission_id']); 88 | }); 89 | } 90 | }; 91 | -------------------------------------------------------------------------------- /app/Livewire/PasswordForm.php: -------------------------------------------------------------------------------- 1 | validate([ 24 | 'current_password' => 'required', 25 | 'password' => 'required|string|min:8|confirmed', 26 | 'password_confirmation' => 'required', 27 | ]); 28 | 29 | $user = Auth::user(); 30 | 31 | // Check current password 32 | if (!Hash::check($this->current_password, $user->password)) { 33 | $this->addError('current_password', 'The current password is incorrect.'); 34 | return; 35 | } 36 | 37 | // Update password 38 | $user->update([ 39 | 'password' => Hash::make($this->password), 40 | ]); 41 | 42 | // Clear form fields 43 | $this->reset(['current_password', 'password', 'password_confirmation']); 44 | 45 | // Reset visibility toggles 46 | $this->show_current_password = false; 47 | $this->show_new_password = false; 48 | $this->show_confirm_password = false; 49 | 50 | $this->showSuccessToast('Password updated successfully!'); 51 | $this->dispatch('$refresh'); 52 | } 53 | 54 | public function toggleCurrentPasswordVisibility() 55 | { 56 | $this->show_current_password = !$this->show_current_password; 57 | } 58 | 59 | public function toggleNewPasswordVisibility() 60 | { 61 | $this->show_new_password = !$this->show_new_password; 62 | } 63 | 64 | public function toggleConfirmPasswordVisibility() 65 | { 66 | $this->show_confirm_password = !$this->show_confirm_password; 67 | } 68 | 69 | public function getPasswordStrength() 70 | { 71 | if (empty($this->password)) { 72 | return ['strength' => 0, 'text' => '', 'color' => 'gray']; 73 | } 74 | 75 | $score = 0; 76 | $password = $this->password; 77 | 78 | // Length check 79 | if (strlen($password) >= 8) $score++; 80 | 81 | // Character variety checks 82 | if (preg_match('/[a-z]/', $password)) $score++; 83 | if (preg_match('/[A-Z]/', $password)) $score++; 84 | if (preg_match('/[0-9]/', $password)) $score++; 85 | if (preg_match('/[^a-zA-Z0-9]/', $password)) $score++; 86 | 87 | // Determine strength 88 | if ($score <= 2) { 89 | return ['strength' => 25, 'text' => 'Weak', 'color' => 'red']; 90 | } elseif ($score <= 3) { 91 | return ['strength' => 50, 'text' => 'Fair', 'color' => 'yellow']; 92 | } elseif ($score <= 4) { 93 | return ['strength' => 75, 'text' => 'Good', 'color' => 'blue']; 94 | } else { 95 | return ['strength' => 100, 'text' => 'Strong', 'color' => 'green']; 96 | } 97 | } 98 | 99 | public function render() 100 | { 101 | return view('livewire.password-form', [ 102 | 'passwordStrength' => $this->getPasswordStrength() 103 | ]); 104 | } 105 | } -------------------------------------------------------------------------------- /resources/views/livewire/profile-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |
5 |

Profile Information

6 |

Update your account's profile information and email address.

7 |
8 |
9 | {{ substr($name ?? 'U', 0, 2) }} 10 |
11 |
12 | 13 | 14 |
15 | 16 |
17 | 18 |
19 | 22 | 29 | @error('name') 30 |

{{ $message }}

31 | @enderror 32 |
33 | 34 | 35 |
36 | 39 | 46 | @error('email') 47 |

{{ $message }}

48 | @enderror 49 |
50 |
51 | 52 | 53 |
54 |
55 | 62 | 70 |
71 |
72 |
73 |
-------------------------------------------------------------------------------- /app/Livewire/Users/UserForm.php: -------------------------------------------------------------------------------- 1 | 'required|string|max:255', 27 | 'email' => [ 28 | 'required', 29 | 'email', 30 | Rule::unique('users')->ignore($this->userId), 31 | ], 32 | 'password' => $this->isEditing ? 'nullable|min:8|confirmed' : 'required|min:8|confirmed', 33 | 'is_active' => 'boolean', 34 | 'selectedRoles' => 'array', 35 | ]; 36 | } 37 | 38 | public function mount($userId = null) 39 | { 40 | if ($userId) { 41 | $this->loadUser($userId); 42 | } 43 | } 44 | 45 | public function loadUser($userId) 46 | { 47 | $user = User::with('roles')->findOrFail($userId); 48 | 49 | $this->userId = $user->id; 50 | $this->name = $user->name; 51 | $this->email = $user->email; 52 | $this->is_active = $user->is_active; 53 | $this->selectedRoles = $user->roles->pluck('id')->toArray(); 54 | $this->isEditing = true; 55 | } 56 | 57 | public function openModal($userId = null) 58 | { 59 | $this->resetForm(); 60 | 61 | if ($userId) { 62 | $this->loadUser($userId); 63 | } 64 | 65 | $this->showModal = true; 66 | } 67 | 68 | public function closeModal() 69 | { 70 | $this->showModal = false; 71 | $this->resetForm(); 72 | } 73 | 74 | public function resetForm() 75 | { 76 | $this->userId = null; 77 | $this->name = ''; 78 | $this->email = ''; 79 | $this->password = ''; 80 | $this->password_confirmation = ''; 81 | $this->is_active = true; 82 | $this->selectedRoles = []; 83 | $this->isEditing = false; 84 | $this->resetErrorBag(); 85 | } 86 | 87 | public function save() 88 | { 89 | $this->validate(); 90 | 91 | if ($this->isEditing) { 92 | $user = User::findOrFail($this->userId); 93 | $user->update([ 94 | 'name' => $this->name, 95 | 'email' => $this->email, 96 | 'is_active' => $this->is_active, 97 | ]); 98 | 99 | if ($this->password) { 100 | $user->update(['password' => Hash::make($this->password)]); 101 | } 102 | } else { 103 | $user = User::create([ 104 | 'name' => $this->name, 105 | 'email' => $this->email, 106 | 'password' => Hash::make($this->password), 107 | 'is_active' => $this->is_active, 108 | ]); 109 | } 110 | 111 | $user->roles()->sync($this->selectedRoles); 112 | 113 | session()->flash('message', $this->isEditing ? 'User updated successfully.' : 'User created successfully.'); 114 | 115 | $this->closeModal(); 116 | $this->dispatch('userSaved'); 117 | } 118 | 119 | public function render() 120 | { 121 | $roles = Role::where('is_active', true)->orderBy('name')->get(); 122 | 123 | return view('livewire.users.user-form', compact('roles')); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
{{ __('Register') }}
9 | 10 |
11 |
12 | @csrf 13 | 14 |
15 | 16 | 17 |
18 | 19 | 20 | @error('name') 21 | 22 | {{ $message }} 23 | 24 | @enderror 25 |
26 |
27 | 28 |
29 | 30 | 31 |
32 | 33 | 34 | @error('email') 35 | 36 | {{ $message }} 37 | 38 | @enderror 39 |
40 |
41 | 42 |
43 | 44 | 45 |
46 | 47 | 48 | @error('password') 49 | 50 | {{ $message }} 51 | 52 | @enderror 53 |
54 |
55 | 56 |
57 | 58 | 59 |
60 | 61 |
62 |
63 | 64 |
65 |
66 | 69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | @endsection 78 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_STORE', 'database'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "array", "database", "file", "memcached", 30 | | "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'array' => [ 37 | 'driver' => 'array', 38 | 'serialize' => false, 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'connection' => env('DB_CACHE_CONNECTION'), 44 | 'table' => env('DB_CACHE_TABLE', 'cache'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | 'lock_table' => env('DB_CACHE_LOCK_TABLE'), 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | 'lock_path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 77 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | 'octane' => [ 90 | 'driver' => 'octane', 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Cache Key Prefix 98 | |-------------------------------------------------------------------------- 99 | | 100 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 101 | | stores, there might be other applications using the same cache. For 102 | | that reason, you may prefix every cache key to avoid collisions. 103 | | 104 | */ 105 | 106 | 'prefix' => env('CACHE_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-cache-'), 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'log'), 18 | 19 | /* 20 | |-------------------------------------------------------------------------- 21 | | Mailer Configurations 22 | |-------------------------------------------------------------------------- 23 | | 24 | | Here you may configure all of the mailers used by your application plus 25 | | their respective settings. Several examples have been configured for 26 | | you and you are free to add your own as your application requires. 27 | | 28 | | Laravel supports a variety of mail "transport" drivers that can be used 29 | | when delivering an email. You may specify which one you're using for 30 | | your mailers below. You may also add additional mailers if needed. 31 | | 32 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 33 | | "postmark", "resend", "log", "array", 34 | | "failover", "roundrobin" 35 | | 36 | */ 37 | 38 | 'mailers' => [ 39 | 40 | 'smtp' => [ 41 | 'transport' => 'smtp', 42 | 'scheme' => env('MAIL_SCHEME'), 43 | 'url' => env('MAIL_URL'), 44 | 'host' => env('MAIL_HOST', '127.0.0.1'), 45 | 'port' => env('MAIL_PORT', 2525), 46 | 'username' => env('MAIL_USERNAME'), 47 | 'password' => env('MAIL_PASSWORD'), 48 | 'timeout' => null, 49 | 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 50 | ], 51 | 52 | 'ses' => [ 53 | 'transport' => 'ses', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 59 | // 'client' => [ 60 | // 'timeout' => 5, 61 | // ], 62 | ], 63 | 64 | 'resend' => [ 65 | 'transport' => 'resend', 66 | ], 67 | 68 | 'sendmail' => [ 69 | 'transport' => 'sendmail', 70 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 71 | ], 72 | 73 | 'log' => [ 74 | 'transport' => 'log', 75 | 'channel' => env('MAIL_LOG_CHANNEL'), 76 | ], 77 | 78 | 'array' => [ 79 | 'transport' => 'array', 80 | ], 81 | 82 | 'failover' => [ 83 | 'transport' => 'failover', 84 | 'mailers' => [ 85 | 'smtp', 86 | 'log', 87 | ], 88 | 'retry_after' => 60, 89 | ], 90 | 91 | 'roundrobin' => [ 92 | 'transport' => 'roundrobin', 93 | 'mailers' => [ 94 | 'ses', 95 | 'postmark', 96 | ], 97 | 'retry_after' => 60, 98 | ], 99 | 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Global "From" Address 105 | |-------------------------------------------------------------------------- 106 | | 107 | | You may wish for all emails sent by your application to be sent from 108 | | the same address. Here you may specify a name and address that is 109 | | used globally for all emails that are sent by your application. 110 | | 111 | */ 112 | 113 | 'from' => [ 114 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 115 | 'name' => env('MAIL_FROM_NAME', 'Example'), 116 | ], 117 | 118 | ]; 119 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'database'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection options for every queue backend 24 | | used by your application. An example configuration is provided for 25 | | each backend supported by Laravel. You're also free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'connection' => env('DB_QUEUE_CONNECTION'), 40 | 'table' => env('DB_QUEUE_TABLE', 'jobs'), 41 | 'queue' => env('DB_QUEUE', 'default'), 42 | 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 43 | 'after_commit' => false, 44 | ], 45 | 46 | 'beanstalkd' => [ 47 | 'driver' => 'beanstalkd', 48 | 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), 49 | 'queue' => env('BEANSTALKD_QUEUE', 'default'), 50 | 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 51 | 'block_for' => 0, 52 | 'after_commit' => false, 53 | ], 54 | 55 | 'sqs' => [ 56 | 'driver' => 'sqs', 57 | 'key' => env('AWS_ACCESS_KEY_ID'), 58 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 59 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 60 | 'queue' => env('SQS_QUEUE', 'default'), 61 | 'suffix' => env('SQS_SUFFIX'), 62 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 63 | 'after_commit' => false, 64 | ], 65 | 66 | 'redis' => [ 67 | 'driver' => 'redis', 68 | 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 69 | 'queue' => env('REDIS_QUEUE', 'default'), 70 | 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90), 71 | 'block_for' => null, 72 | 'after_commit' => false, 73 | ], 74 | 75 | ], 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Job Batching 80 | |-------------------------------------------------------------------------- 81 | | 82 | | The following options configure the database and table that store job 83 | | batching information. These options can be updated to any database 84 | | connection and table which has been defined by your application. 85 | | 86 | */ 87 | 88 | 'batching' => [ 89 | 'database' => env('DB_CONNECTION', 'sqlite'), 90 | 'table' => 'job_batches', 91 | ], 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | Failed Queue Jobs 96 | |-------------------------------------------------------------------------- 97 | | 98 | | These options configure the behavior of failed queue job logging so you 99 | | can control how and where failed jobs are stored. Laravel ships with 100 | | support for storing failed jobs in a simple file or in a database. 101 | | 102 | | Supported drivers: "database-uuids", "dynamodb", "file", "null" 103 | | 104 | */ 105 | 106 | 'failed' => [ 107 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 108 | 'database' => env('DB_CONNECTION', 'sqlite'), 109 | 'table' => 'failed_jobs', 110 | ], 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /resources/views/livewire/password-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |
5 |

Password & Security

6 |

Update your password and manage security settings.

7 |
8 |
9 | 10 | 11 | 12 |
13 |
14 | 15 | 16 |
17 | 18 |
19 | 22 | 29 | @error('current_password') 30 |

{{ $message }}

31 | @enderror 32 |
33 | 34 | 35 |
36 | 39 | 46 | @error('password') 47 |

{{ $message }}

48 | @enderror 49 |
50 | 51 | 52 |
53 | 56 | 63 | @error('password_confirmation') 64 |

{{ $message }}

65 | @enderror 66 |
67 | 68 | 69 |
70 |
71 | 78 | 86 |
87 |
88 |
89 |
-------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => env('AUTH_GUARD', 'web'), 18 | 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | which utilizes session storage plus the Eloquent user provider. 29 | | 30 | | All authentication guards have a user provider, which defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | system used by the application. Typically, Eloquent is utilized. 33 | | 34 | | Supported: "session" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | User Providers 48 | |-------------------------------------------------------------------------- 49 | | 50 | | All authentication guards have a user provider, which defines how the 51 | | users are actually retrieved out of your database or other storage 52 | | system used by the application. Typically, Eloquent is utilized. 53 | | 54 | | If you have multiple user tables or models you may configure multiple 55 | | providers to represent the model / table. These providers may then 56 | | be assigned to any extra authentication guards you have defined. 57 | | 58 | | Supported: "database", "eloquent" 59 | | 60 | */ 61 | 62 | 'providers' => [ 63 | 'users' => [ 64 | 'driver' => 'eloquent', 65 | 'model' => env('AUTH_MODEL', App\Domains\User\Models\User::class), 66 | ], 67 | 68 | // 'users' => [ 69 | // 'driver' => 'database', 70 | // 'table' => 'users', 71 | // ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | These configuration options specify the behavior of Laravel's password 80 | | reset functionality, including the table utilized for token storage 81 | | and the user provider that is invoked to actually retrieve users. 82 | | 83 | | The expiry time is the number of minutes that each reset token will be 84 | | considered valid. This security feature keeps tokens short-lived so 85 | | they have less time to be guessed. You may change this as needed. 86 | | 87 | | The throttle setting is the number of seconds a user must wait before 88 | | generating more password reset tokens. This prevents the user from 89 | | quickly generating a very large amount of password reset tokens. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), 97 | 'expire' => 60, 98 | 'throttle' => 60, 99 | ], 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Password Confirmation Timeout 105 | |-------------------------------------------------------------------------- 106 | | 107 | | Here you may define the number of seconds before a password confirmation 108 | | window expires and users are asked to re-enter their password via the 109 | | confirmation screen. By default, the timeout lasts for three hours. 110 | | 111 | */ 112 | 113 | 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), 114 | 115 | ]; 116 | -------------------------------------------------------------------------------- /resources/views/profile/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 | 6 |
7 |
8 |
9 |
10 | 11 |
12 |
13 |
14 |

15 | Profile Settings 16 |

17 |

Manage your account information

18 |
19 |
20 | {{ substr(auth()->user()->name, 0, 2) }} 21 |
22 |
23 |
24 |
25 | 26 | 27 |
28 |
29 | 43 |
44 | 45 | 46 |
47 | 48 |
49 | 50 |
51 | 52 | 53 | 56 |
57 |
58 |
59 | 60 | 82 | 83 | 102 | @endsection -------------------------------------------------------------------------------- /app/Livewire/Users/UserList.php: -------------------------------------------------------------------------------- 1 | ['except' => ''], 24 | 'showInactive' => ['except' => false], 25 | ]; 26 | 27 | public function updatingSearch() 28 | { 29 | $this->resetPage(); 30 | } 31 | 32 | public function sortBy($field) 33 | { 34 | if ($this->sortField === $field) { 35 | $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; 36 | } else { 37 | $this->sortDirection = 'asc'; 38 | } 39 | 40 | $this->sortField = $field; 41 | } 42 | 43 | public function toggleUserStatus($userId) 44 | { 45 | $user = User::findOrFail($userId); 46 | $oldStatus = $user->is_active; 47 | $newStatus = !$user->is_active; 48 | $status = $oldStatus ? 'deactivated' : 'activated'; 49 | 50 | $user->update(['is_active' => $newStatus]); 51 | 52 | // Log the action 53 | LoggerService::logUserAction( 54 | 'toggle_status', 55 | 'User', 56 | $userId, 57 | [ 58 | 'old_status' => $oldStatus, 59 | 'new_status' => $newStatus, 60 | 'target_user_email' => $user->email 61 | ] 62 | ); 63 | 64 | // Clear user cache 65 | CacheService::clearUserCache($userId); 66 | CacheService::clearDashboardCache(); 67 | 68 | // Refresh the component to show updated data 69 | $this->dispatch('$refresh'); 70 | 71 | $this->showSuccessToast("User {$status} successfully!"); 72 | } 73 | 74 | public function confirmDeleteUser($userId) 75 | { 76 | $user = User::findOrFail($userId); 77 | $this->showConfirm( 78 | 'Delete User', 79 | "Are you sure you want to delete user '{$user->name}'? This action cannot be undone.", 80 | 'deleteUser', 81 | ['userId' => $userId], 82 | 'Yes, delete it!', 83 | 'Cancel' 84 | ); 85 | } 86 | 87 | public function deleteUser($params) 88 | { 89 | $userId = $params['userId']; 90 | $user = User::findOrFail($userId); 91 | 92 | // Log the action before deletion 93 | LoggerService::logUserAction( 94 | 'delete', 95 | 'User', 96 | $userId, 97 | [ 98 | 'deleted_user_email' => $user->email, 99 | 'deleted_user_name' => $user->name, 100 | 'had_roles' => $user->roles->pluck('name')->toArray() 101 | ], 102 | 'warning' 103 | ); 104 | 105 | // Clear user cache before deletion 106 | CacheService::clearUserCache($userId); 107 | CacheService::clearDashboardCache(); 108 | 109 | $user->delete(); 110 | 111 | // Refresh the component to show updated data 112 | $this->dispatch('$refresh'); 113 | 114 | $this->showSuccessToast('User deleted successfully!'); 115 | } 116 | 117 | public function render() 118 | { 119 | // Optimize query with proper select and joins 120 | $users = User::query() 121 | ->select(['id', 'name', 'email', 'is_active', 'created_at', 'updated_at']) 122 | ->when($this->search, function ($query) { 123 | $query->where(function ($q) { 124 | $q->where('name', 'like', '%' . $this->search . '%') 125 | ->orWhere('email', 'like', '%' . $this->search . '%'); 126 | }); 127 | }) 128 | ->when(!$this->showInactive, function ($query) { 129 | $query->where('is_active', true); 130 | }) 131 | ->with(['roles:id,name,display_name']) // Only select needed columns 132 | ->orderBy($this->sortField, $this->sortDirection) 133 | ->paginate($this->perPage); 134 | 135 | return view('livewire.users.user-list', compact('users')); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | the application so that it's available within Artisan commands. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. The timezone 64 | | is set to "UTC" by default as it is suitable for most use cases. 65 | | 66 | */ 67 | 68 | 'timezone' => 'UTC', 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by Laravel's translation / localization methods. This option can be 77 | | set to any locale for which you plan to have translation strings. 78 | | 79 | */ 80 | 81 | 'locale' => env('APP_LOCALE', 'en'), 82 | 83 | 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), 84 | 85 | 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), 86 | 87 | /* 88 | |-------------------------------------------------------------------------- 89 | | Encryption Key 90 | |-------------------------------------------------------------------------- 91 | | 92 | | This key is utilized by Laravel's encryption services and should be set 93 | | to a random, 32 character string to ensure that all encrypted values 94 | | are secure. You should do this prior to deploying the application. 95 | | 96 | */ 97 | 98 | 'cipher' => 'AES-256-CBC', 99 | 100 | 'key' => env('APP_KEY'), 101 | 102 | 'previous_keys' => [ 103 | ...array_filter( 104 | explode(',', (string) env('APP_PREVIOUS_KEYS', '')) 105 | ), 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Maintenance Mode Driver 111 | |-------------------------------------------------------------------------- 112 | | 113 | | These configuration options determine the driver used to determine and 114 | | manage Laravel's "maintenance mode" status. The "cache" driver will 115 | | allow maintenance mode to be controlled across multiple machines. 116 | | 117 | | Supported drivers: "file", "cache" 118 | | 119 | */ 120 | 121 | 'maintenance' => [ 122 | 'driver' => env('APP_MAINTENANCE_DRIVER', 'file'), 123 | 'store' => env('APP_MAINTENANCE_STORE', 'database'), 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Deprecations Log Channel 26 | |-------------------------------------------------------------------------- 27 | | 28 | | This option controls the log channel that should be used to log warnings 29 | | regarding deprecated PHP and library features. This allows you to get 30 | | your application ready for upcoming major versions of dependencies. 31 | | 32 | */ 33 | 34 | 'deprecations' => [ 35 | 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 36 | 'trace' => env('LOG_DEPRECATIONS_TRACE', false), 37 | ], 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Log Channels 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here you may configure the log channels for your application. Laravel 45 | | utilizes the Monolog PHP logging library, which includes a variety 46 | | of powerful log handlers and formatters that you're free to use. 47 | | 48 | | Available drivers: "single", "daily", "slack", "syslog", 49 | | "errorlog", "monolog", "custom", "stack" 50 | | 51 | */ 52 | 53 | 'channels' => [ 54 | 55 | 'stack' => [ 56 | 'driver' => 'stack', 57 | 'channels' => explode(',', (string) env('LOG_STACK', 'single')), 58 | 'ignore_exceptions' => false, 59 | ], 60 | 61 | 'single' => [ 62 | 'driver' => 'single', 63 | 'path' => storage_path('logs/laravel.log'), 64 | 'level' => env('LOG_LEVEL', 'debug'), 65 | 'replace_placeholders' => true, 66 | ], 67 | 68 | 'daily' => [ 69 | 'driver' => 'daily', 70 | 'path' => storage_path('logs/laravel.log'), 71 | 'level' => env('LOG_LEVEL', 'debug'), 72 | 'days' => env('LOG_DAILY_DAYS', 14), 73 | 'replace_placeholders' => true, 74 | ], 75 | 76 | 'slack' => [ 77 | 'driver' => 'slack', 78 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 79 | 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), 80 | 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), 81 | 'level' => env('LOG_LEVEL', 'critical'), 82 | 'replace_placeholders' => true, 83 | ], 84 | 85 | 'papertrail' => [ 86 | 'driver' => 'monolog', 87 | 'level' => env('LOG_LEVEL', 'debug'), 88 | 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), 89 | 'handler_with' => [ 90 | 'host' => env('PAPERTRAIL_URL'), 91 | 'port' => env('PAPERTRAIL_PORT'), 92 | 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 93 | ], 94 | 'processors' => [PsrLogMessageProcessor::class], 95 | ], 96 | 97 | 'stderr' => [ 98 | 'driver' => 'monolog', 99 | 'level' => env('LOG_LEVEL', 'debug'), 100 | 'handler' => StreamHandler::class, 101 | 'handler_with' => [ 102 | 'stream' => 'php://stderr', 103 | ], 104 | 'formatter' => env('LOG_STDERR_FORMATTER'), 105 | 'processors' => [PsrLogMessageProcessor::class], 106 | ], 107 | 108 | 'syslog' => [ 109 | 'driver' => 'syslog', 110 | 'level' => env('LOG_LEVEL', 'debug'), 111 | 'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER), 112 | 'replace_placeholders' => true, 113 | ], 114 | 115 | 'errorlog' => [ 116 | 'driver' => 'errorlog', 117 | 'level' => env('LOG_LEVEL', 'debug'), 118 | 'replace_placeholders' => true, 119 | ], 120 | 121 | 'null' => [ 122 | 'driver' => 'monolog', 123 | 'handler' => NullHandler::class, 124 | ], 125 | 126 | 'emergency' => [ 127 | 'path' => storage_path('logs/laravel.log'), 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /app/Shared/Services/CacheService.php: -------------------------------------------------------------------------------- 1 | roles()->with('permissions')->get(); 18 | }); 19 | } 20 | 21 | public static function getUserPermissions($userId, $ttl = self::DEFAULT_TTL) 22 | { 23 | return Cache::remember("user.{$userId}.permissions", $ttl, function () use ($userId) { 24 | $user = \App\Domains\User\Models\User::find($userId); 25 | if (!$user) { 26 | return collect(); 27 | } 28 | 29 | return $user->roles() 30 | ->with('permissions') 31 | ->get() 32 | ->pluck('permissions') 33 | ->flatten() 34 | ->where('is_active', true) 35 | ->unique('id') 36 | ->values(); 37 | }); 38 | } 39 | 40 | public static function getRolePermissions($roleId, $ttl = self::DEFAULT_TTL) 41 | { 42 | return Cache::remember("role.{$roleId}.permissions", $ttl, function () use ($roleId) { 43 | return \App\Domains\Role\Models\Role::find($roleId)?->permissions()->where('is_active', true)->get(); 44 | }); 45 | } 46 | 47 | public static function getActiveRoles($ttl = self::LONG_TTL) 48 | { 49 | return Cache::remember('roles.active', $ttl, function () { 50 | return \App\Domains\Role\Models\Role::where('is_active', true) 51 | ->orderBy('name') 52 | ->get(); 53 | }); 54 | } 55 | 56 | public static function getActivePermissions($ttl = self::LONG_TTL) 57 | { 58 | return Cache::remember('permissions.active', $ttl, function () { 59 | return \App\Domains\Permission\Models\Permission::where('is_active', true) 60 | ->orderBy('group') 61 | ->orderBy('name') 62 | ->get(); 63 | }); 64 | } 65 | 66 | public static function getPermissionsByGroup($ttl = self::LONG_TTL) 67 | { 68 | return Cache::remember('permissions.by_group', $ttl, function () { 69 | return \App\Domains\Permission\Models\Permission::where('is_active', true) 70 | ->orderBy('group') 71 | ->orderBy('name') 72 | ->get() 73 | ->groupBy('group'); 74 | }); 75 | } 76 | 77 | public static function clearUserCache($userId) 78 | { 79 | Cache::forget("user.{$userId}.roles"); 80 | Cache::forget("user.{$userId}.permissions"); 81 | } 82 | 83 | public static function clearRoleCache($roleId) 84 | { 85 | Cache::forget("role.{$roleId}.permissions"); 86 | self::clearSystemCache(); 87 | } 88 | 89 | public static function clearSystemCache() 90 | { 91 | Cache::forget('roles.active'); 92 | Cache::forget('permissions.active'); 93 | Cache::forget('permissions.by_group'); 94 | } 95 | 96 | public static function clearAllUserCaches() 97 | { 98 | $pattern = 'user.*.roles'; 99 | self::clearCacheByPattern($pattern); 100 | 101 | $pattern = 'user.*.permissions'; 102 | self::clearCacheByPattern($pattern); 103 | } 104 | 105 | private static function clearCacheByPattern($pattern) 106 | { 107 | try { 108 | if (config('cache.default') === 'redis') { 109 | $keys = Redis::keys(config('cache.prefix') . ':' . $pattern); 110 | if (!empty($keys)) { 111 | Redis::del($keys); 112 | } 113 | } else { 114 | // For other cache drivers, we'll need to clear all cache 115 | Cache::flush(); 116 | } 117 | } catch (\Exception $e) { 118 | // Fallback to cache flush if pattern deletion fails 119 | Cache::flush(); 120 | } 121 | } 122 | 123 | public static function getDashboardStats($ttl = self::SHORT_TTL) 124 | { 125 | return Cache::remember('dashboard.stats', $ttl, function () { 126 | return [ 127 | 'total_users' => \App\Domains\User\Models\User::count(), 128 | 'active_users' => \App\Domains\User\Models\User::where('is_active', true)->count(), 129 | 'total_roles' => \App\Domains\Role\Models\Role::count(), 130 | 'active_roles' => \App\Domains\Role\Models\Role::where('is_active', true)->count(), 131 | 'total_permissions' => \App\Domains\Permission\Models\Permission::count(), 132 | 'recent_users' => \App\Domains\User\Models\User::latest()->take(5)->get(), 133 | ]; 134 | }); 135 | } 136 | 137 | public static function clearDashboardCache() 138 | { 139 | Cache::forget('dashboard.stats'); 140 | } 141 | } -------------------------------------------------------------------------------- /app/Livewire/Roles/RoleForm.php: -------------------------------------------------------------------------------- 1 | [ 27 | 'required', 28 | 'string', 29 | 'max:255', 30 | 'regex:/^[a-z0-9-]+$/', 31 | Rule::unique('roles')->ignore($this->roleId), 32 | ], 33 | 'display_name' => 'required|string|max:255', 34 | 'description' => 'nullable|string|max:500', 35 | 'is_active' => 'boolean', 36 | 'selectedPermissions' => 'array', 37 | ]; 38 | } 39 | 40 | protected $messages = [ 41 | 'name.regex' => 'Role name must contain only lowercase letters, numbers, and hyphens.', 42 | ]; 43 | 44 | public function mount($roleId = null) 45 | { 46 | if ($roleId) { 47 | $this->loadRole($roleId); 48 | } 49 | } 50 | 51 | public function loadRole($roleId) 52 | { 53 | $role = Role::findOrFail($roleId); 54 | 55 | $this->roleId = $role->id; 56 | $this->name = $role->name; 57 | $this->display_name = $role->display_name; 58 | $this->description = $role->description; 59 | $this->is_active = $role->is_active; 60 | $this->selectedPermissions = $role->permissions()->pluck('permissions.id')->toArray(); 61 | $this->isEditing = true; 62 | } 63 | 64 | public function openModal($roleId = null) 65 | { 66 | $this->resetForm(); 67 | 68 | if ($roleId) { 69 | $this->loadRole($roleId); 70 | } 71 | 72 | $this->showModal = true; 73 | } 74 | 75 | public function closeModal() 76 | { 77 | $this->showModal = false; 78 | $this->resetForm(); 79 | } 80 | 81 | public function resetForm() 82 | { 83 | $this->roleId = null; 84 | $this->name = ''; 85 | $this->display_name = ''; 86 | $this->description = ''; 87 | $this->is_active = true; 88 | $this->selectedPermissions = []; 89 | $this->isEditing = false; 90 | $this->resetErrorBag(); 91 | } 92 | 93 | public function selectAllInGroup($group) 94 | { 95 | // Get permissions for this group from database 96 | $groupPermissions = Permission::where('is_active', true) 97 | ->where('group', $group) 98 | ->get(); 99 | $groupIds = $groupPermissions->pluck('id')->toArray(); 100 | 101 | // Check if all permissions in group are already selected 102 | $allSelected = !array_diff($groupIds, $this->selectedPermissions); 103 | 104 | if ($allSelected) { 105 | // Remove all permissions in this group 106 | $this->selectedPermissions = array_diff($this->selectedPermissions, $groupIds); 107 | } else { 108 | // Add all permissions in this group 109 | $this->selectedPermissions = array_unique(array_merge($this->selectedPermissions, $groupIds)); 110 | } 111 | } 112 | 113 | public function save() 114 | { 115 | $this->validate(); 116 | 117 | // Prevent editing super-admin role 118 | if ($this->isEditing && $this->name === 'super-admin') { 119 | session()->flash('error', 'Cannot modify super-admin role.'); 120 | return; 121 | } 122 | 123 | if ($this->isEditing) { 124 | $role = Role::findOrFail($this->roleId); 125 | $role->update([ 126 | 'name' => $this->name, 127 | 'display_name' => $this->display_name, 128 | 'description' => $this->description, 129 | 'is_active' => $this->is_active, 130 | ]); 131 | } else { 132 | $role = Role::create([ 133 | 'name' => $this->name, 134 | 'display_name' => $this->display_name, 135 | 'description' => $this->description, 136 | 'is_active' => $this->is_active, 137 | ]); 138 | } 139 | 140 | $role->permissions()->sync($this->selectedPermissions); 141 | 142 | session()->flash('message', $this->isEditing ? 'Role updated successfully.' : 'Role created successfully.'); 143 | 144 | $this->closeModal(); 145 | $this->dispatch('roleSaved'); 146 | } 147 | 148 | public function render() 149 | { 150 | // Get permissions grouped by group for the view 151 | $permissions = Permission::where('is_active', true) 152 | ->orderBy('group') 153 | ->orderBy('name') 154 | ->get(); 155 | 156 | $permissionsByGroup = $permissions->groupBy('group'); 157 | 158 | return view('livewire.roles.role-form', compact('permissionsByGroup')); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /app/Livewire/Roles/RoleList.php: -------------------------------------------------------------------------------- 1 | ['except' => ''], 25 | 'showInactive' => ['except' => false], 26 | 'filterByPermissions' => ['except' => ''], 27 | ]; 28 | 29 | public function updatingSearch() 30 | { 31 | $this->resetPage(); 32 | } 33 | 34 | public function updatingFilterByPermissions() 35 | { 36 | $this->resetPage(); 37 | } 38 | 39 | public function sortBy($field) 40 | { 41 | if ($this->sortField === $field) { 42 | $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; 43 | } else { 44 | $this->sortDirection = 'asc'; 45 | } 46 | 47 | $this->sortField = $field; 48 | } 49 | 50 | public function toggleRoleStatus($roleId) 51 | { 52 | $role = Role::findOrFail($roleId); 53 | $oldStatus = $role->is_active; 54 | $newStatus = !$role->is_active; 55 | $status = $oldStatus ? 'deactivated' : 'activated'; 56 | 57 | $role->update(['is_active' => $newStatus]); 58 | 59 | // Log the action 60 | LoggerService::logUserAction( 61 | 'toggle_status', 62 | 'Role', 63 | $roleId, 64 | [ 65 | 'old_status' => $oldStatus, 66 | 'new_status' => $newStatus, 67 | 'role_name' => $role->name 68 | ] 69 | ); 70 | 71 | // Clear related caches 72 | CacheService::clearRoleCache($roleId); 73 | CacheService::clearAllUserCaches(); 74 | CacheService::clearDashboardCache(); 75 | 76 | // Refresh the component to show updated data 77 | $this->dispatch('$refresh'); 78 | 79 | $this->showSuccessToast("Role {$status} successfully!"); 80 | } 81 | 82 | public function confirmDeleteRole($roleId) 83 | { 84 | $role = Role::findOrFail($roleId); 85 | 86 | // Prevent deletion of super-admin role 87 | if ($role->name === 'super-admin') { 88 | $this->showErrorToast('Cannot delete super-admin role.'); 89 | return; 90 | } 91 | 92 | $this->showConfirm( 93 | 'Delete Role', 94 | "Are you sure you want to delete role '{$role->display_name}'? This action cannot be undone.", 95 | 'deleteRole', 96 | ['roleId' => $roleId], 97 | 'Yes, delete it!', 98 | 'Cancel' 99 | ); 100 | } 101 | 102 | public function deleteRole($params) 103 | { 104 | $roleId = $params['roleId']; 105 | $role = Role::findOrFail($roleId); 106 | 107 | // Log the action before deletion 108 | LoggerService::logUserAction( 109 | 'delete', 110 | 'Role', 111 | $roleId, 112 | [ 113 | 'deleted_role_name' => $role->name, 114 | 'deleted_role_display_name' => $role->display_name, 115 | 'had_permissions' => $role->permissions->pluck('name')->toArray() 116 | ], 117 | 'warning' 118 | ); 119 | 120 | // Clear related caches before deletion 121 | CacheService::clearRoleCache($roleId); 122 | CacheService::clearAllUserCaches(); 123 | CacheService::clearDashboardCache(); 124 | 125 | $role->delete(); 126 | 127 | // Refresh the component to show updated data 128 | $this->dispatch('$refresh'); 129 | 130 | $this->showSuccessToast('Role deleted successfully!'); 131 | } 132 | 133 | public function render() 134 | { 135 | // Optimize query with proper select and subqueries for counts 136 | $roles = Role::query() 137 | ->select([ 138 | 'id', 'name', 'display_name', 'description', 'is_active', 139 | 'created_at', 'updated_at' 140 | ]) 141 | ->when($this->search, function ($query) { 142 | $query->where(function ($q) { 143 | $q->where('name', 'like', '%' . $this->search . '%') 144 | ->orWhere('display_name', 'like', '%' . $this->search . '%') 145 | ->orWhere('description', 'like', '%' . $this->search . '%'); 146 | }); 147 | }) 148 | ->when(!$this->showInactive, function ($query) { 149 | $query->where('is_active', true); 150 | }) 151 | ->when($this->filterByPermissions, function ($query) { 152 | $query->whereHas('permissions', function ($q) { 153 | $q->where('group', $this->filterByPermissions); 154 | }); 155 | }) 156 | ->withCount(['permissions', 'users']) // Use withCount for better performance 157 | ->orderBy($this->sortField, $this->sortDirection) 158 | ->paginate($this->perPage); 159 | 160 | $permissionGroups = ['users', 'roles', 'permissions', 'system']; 161 | 162 | return view('livewire.roles.role-list', compact('roles', 'permissionGroups')); 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /resources/views/livewire/users/user-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if($showModal) 3 |
4 |
5 |
6 |
7 |

8 | {{ $isEditing ? 'Edit User' : 'Create User' }} 9 |

10 | 15 |
16 | 17 |
18 |
19 | 20 | 21 | @error('name') {{ $message }} @enderror 22 |
23 | 24 |
25 | 26 | 27 | @error('email') {{ $message }} @enderror 28 |
29 | 30 |
31 | 34 | 35 | @error('password') {{ $message }} @enderror 36 |
37 | 38 |
39 | 40 | 41 | @error('password_confirmation') {{ $message }} @enderror 42 |
43 | 44 |
45 | 49 |
50 | 51 |
52 | 53 |
54 | @foreach($roles as $role) 55 | 69 | @endforeach 70 |
71 | @error('selectedRoles') {{ $message }} @enderror 72 |
73 | 74 |
75 | 78 | 81 |
82 |
83 |
84 |
85 |
86 | @endif 87 |
88 | 89 | 96 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'sqlite'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Database Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Below are all of the database connections defined for your application. 27 | | An example configuration is provided for each database system which 28 | | is supported by Laravel. You're free to add / remove connections. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sqlite' => [ 35 | 'driver' => 'sqlite', 36 | 'url' => env('DB_URL'), 37 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 38 | 'prefix' => '', 39 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 40 | 'busy_timeout' => null, 41 | 'journal_mode' => null, 42 | 'synchronous' => null, 43 | ], 44 | 45 | 'mysql' => [ 46 | 'driver' => 'mysql', 47 | 'url' => env('DB_URL'), 48 | 'host' => env('DB_HOST', '127.0.0.1'), 49 | 'port' => env('DB_PORT', '3306'), 50 | 'database' => env('DB_DATABASE', 'laravel'), 51 | 'username' => env('DB_USERNAME', 'root'), 52 | 'password' => env('DB_PASSWORD', ''), 53 | 'unix_socket' => env('DB_SOCKET', ''), 54 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 55 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 56 | 'prefix' => '', 57 | 'prefix_indexes' => true, 58 | 'strict' => true, 59 | 'engine' => null, 60 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 61 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 62 | ]) : [], 63 | ], 64 | 65 | 'mariadb' => [ 66 | 'driver' => 'mariadb', 67 | 'url' => env('DB_URL'), 68 | 'host' => env('DB_HOST', '127.0.0.1'), 69 | 'port' => env('DB_PORT', '3306'), 70 | 'database' => env('DB_DATABASE', 'laravel'), 71 | 'username' => env('DB_USERNAME', 'root'), 72 | 'password' => env('DB_PASSWORD', ''), 73 | 'unix_socket' => env('DB_SOCKET', ''), 74 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 75 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 76 | 'prefix' => '', 77 | 'prefix_indexes' => true, 78 | 'strict' => true, 79 | 'engine' => null, 80 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 81 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 82 | ]) : [], 83 | ], 84 | 85 | 'pgsql' => [ 86 | 'driver' => 'pgsql', 87 | 'url' => env('DB_URL'), 88 | 'host' => env('DB_HOST', '127.0.0.1'), 89 | 'port' => env('DB_PORT', '5432'), 90 | 'database' => env('DB_DATABASE', 'laravel'), 91 | 'username' => env('DB_USERNAME', 'root'), 92 | 'password' => env('DB_PASSWORD', ''), 93 | 'charset' => env('DB_CHARSET', 'utf8'), 94 | 'prefix' => '', 95 | 'prefix_indexes' => true, 96 | 'search_path' => 'public', 97 | 'sslmode' => 'prefer', 98 | ], 99 | 100 | 'sqlsrv' => [ 101 | 'driver' => 'sqlsrv', 102 | 'url' => env('DB_URL'), 103 | 'host' => env('DB_HOST', 'localhost'), 104 | 'port' => env('DB_PORT', '1433'), 105 | 'database' => env('DB_DATABASE', 'laravel'), 106 | 'username' => env('DB_USERNAME', 'root'), 107 | 'password' => env('DB_PASSWORD', ''), 108 | 'charset' => env('DB_CHARSET', 'utf8'), 109 | 'prefix' => '', 110 | 'prefix_indexes' => true, 111 | // 'encrypt' => env('DB_ENCRYPT', 'yes'), 112 | // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), 113 | ], 114 | 115 | ], 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Migration Repository Table 120 | |-------------------------------------------------------------------------- 121 | | 122 | | This table keeps track of all the migrations that have already run for 123 | | your application. Using this information, we can determine which of 124 | | the migrations on disk haven't actually been run on the database. 125 | | 126 | */ 127 | 128 | 'migrations' => [ 129 | 'table' => 'migrations', 130 | 'update_date_on_publish' => true, 131 | ], 132 | 133 | /* 134 | |-------------------------------------------------------------------------- 135 | | Redis Databases 136 | |-------------------------------------------------------------------------- 137 | | 138 | | Redis is an open source, fast, and advanced key-value store that also 139 | | provides a richer body of commands than a typical key-value system 140 | | such as Memcached. You may define your connection settings here. 141 | | 142 | */ 143 | 144 | 'redis' => [ 145 | 146 | 'client' => env('REDIS_CLIENT', 'phpredis'), 147 | 148 | 'options' => [ 149 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 150 | 'prefix' => env('REDIS_PREFIX', Str::slug((string) env('APP_NAME', 'laravel')).'-database-'), 151 | 'persistent' => env('REDIS_PERSISTENT', false), 152 | ], 153 | 154 | 'default' => [ 155 | 'url' => env('REDIS_URL'), 156 | 'host' => env('REDIS_HOST', '127.0.0.1'), 157 | 'username' => env('REDIS_USERNAME'), 158 | 'password' => env('REDIS_PASSWORD'), 159 | 'port' => env('REDIS_PORT', '6379'), 160 | 'database' => env('REDIS_DB', '0'), 161 | ], 162 | 163 | 'cache' => [ 164 | 'url' => env('REDIS_URL'), 165 | 'host' => env('REDIS_HOST', '127.0.0.1'), 166 | 'username' => env('REDIS_USERNAME'), 167 | 'password' => env('REDIS_PASSWORD'), 168 | 'port' => env('REDIS_PORT', '6379'), 169 | 'database' => env('REDIS_CACHE_DB', '1'), 170 | ], 171 | 172 | ], 173 | 174 | ]; 175 | -------------------------------------------------------------------------------- /app/Shared/Services/LoggerService.php: -------------------------------------------------------------------------------- 1 | Auth::id(), 24 | 'user_email' => Auth::user()?->email, 25 | 'ip_address' => Request::ip(), 26 | 'user_agent' => Request::userAgent(), 27 | 'url' => Request::fullUrl(), 28 | 'method' => Request::method(), 29 | 'timestamp' => now()->toISOString(), 30 | 'session_id' => session()->getId(), 31 | ]; 32 | } 33 | 34 | public static function logUserAction(string $action, string $entity, $entityId = null, array $data = [], string $level = self::LEVEL_INFO) 35 | { 36 | $context = array_merge(self::getContext(), [ 37 | 'action' => $action, 38 | 'entity' => $entity, 39 | 'entity_id' => $entityId, 40 | 'data' => $data, 41 | 'category' => 'user_action' 42 | ]); 43 | 44 | Log::log($level, "User action: {$action} on {$entity}" . ($entityId ? " (ID: {$entityId})" : ''), $context); 45 | } 46 | 47 | public static function logSecurityEvent(string $event, string $level = self::LEVEL_WARNING, array $data = []) 48 | { 49 | $context = array_merge(self::getContext(), [ 50 | 'event' => $event, 51 | 'data' => $data, 52 | 'category' => 'security' 53 | ]); 54 | 55 | Log::log($level, "Security event: {$event}", $context); 56 | } 57 | 58 | public static function logSystemEvent(string $event, string $level = self::LEVEL_INFO, array $data = []) 59 | { 60 | $context = array_merge(self::getContext(), [ 61 | 'event' => $event, 62 | 'data' => $data, 63 | 'category' => 'system' 64 | ]); 65 | 66 | Log::log($level, "System event: {$event}", $context); 67 | } 68 | 69 | public static function logDatabaseOperation(string $operation, string $table, $recordId = null, array $data = [], string $level = self::LEVEL_INFO) 70 | { 71 | $context = array_merge(self::getContext(), [ 72 | 'operation' => $operation, 73 | 'table' => $table, 74 | 'record_id' => $recordId, 75 | 'data' => $data, 76 | 'category' => 'database' 77 | ]); 78 | 79 | Log::log($level, "Database operation: {$operation} on {$table}" . ($recordId ? " (ID: {$recordId})" : ''), $context); 80 | } 81 | 82 | public static function logAPIRequest(string $endpoint, string $method, array $data = [], string $level = self::LEVEL_INFO) 83 | { 84 | $context = array_merge(self::getContext(), [ 85 | 'endpoint' => $endpoint, 86 | 'api_method' => $method, 87 | 'request_data' => $data, 88 | 'category' => 'api' 89 | ]); 90 | 91 | Log::log($level, "API request: {$method} {$endpoint}", $context); 92 | } 93 | 94 | public static function logPerformance(string $operation, float $executionTime, array $data = []) 95 | { 96 | $context = array_merge(self::getContext(), [ 97 | 'operation' => $operation, 98 | 'execution_time' => $executionTime, 99 | 'data' => $data, 100 | 'category' => 'performance' 101 | ]); 102 | 103 | $level = $executionTime > 5 ? self::LEVEL_WARNING : self::LEVEL_INFO; 104 | 105 | Log::log($level, "Performance: {$operation} took {$executionTime}s", $context); 106 | } 107 | 108 | public static function logAuthentication(string $event, ?string $email = null, string $level = self::LEVEL_INFO, array $data = []) 109 | { 110 | $context = array_merge(self::getContext(), [ 111 | 'auth_event' => $event, 112 | 'email' => $email ?? Auth::user()?->email, 113 | 'data' => $data, 114 | 'category' => 'authentication' 115 | ]); 116 | 117 | Log::log($level, "Authentication: {$event}" . ($email ? " for {$email}" : ''), $context); 118 | } 119 | 120 | public static function logError(\Throwable $exception, array $data = []) 121 | { 122 | $context = array_merge(self::getContext(), [ 123 | 'exception_class' => get_class($exception), 124 | 'exception_message' => $exception->getMessage(), 125 | 'exception_code' => $exception->getCode(), 126 | 'exception_file' => $exception->getFile(), 127 | 'exception_line' => $exception->getLine(), 128 | 'exception_trace' => $exception->getTraceAsString(), 129 | 'data' => $data, 130 | 'category' => 'error' 131 | ]); 132 | 133 | Log::error("Exception: {$exception->getMessage()}", $context); 134 | } 135 | 136 | public static function emergency(string $message, array $context = []) 137 | { 138 | Log::emergency($message, array_merge(self::getContext(), $context)); 139 | } 140 | 141 | public static function alert(string $message, array $context = []) 142 | { 143 | Log::alert($message, array_merge(self::getContext(), $context)); 144 | } 145 | 146 | public static function critical(string $message, array $context = []) 147 | { 148 | Log::critical($message, array_merge(self::getContext(), $context)); 149 | } 150 | 151 | public static function error(string $message, array $context = []) 152 | { 153 | Log::error($message, array_merge(self::getContext(), $context)); 154 | } 155 | 156 | public static function warning(string $message, array $context = []) 157 | { 158 | Log::warning($message, array_merge(self::getContext(), $context)); 159 | } 160 | 161 | public static function notice(string $message, array $context = []) 162 | { 163 | Log::notice($message, array_merge(self::getContext(), $context)); 164 | } 165 | 166 | public static function info(string $message, array $context = []) 167 | { 168 | Log::info($message, array_merge(self::getContext(), $context)); 169 | } 170 | 171 | public static function debug(string $message, array $context = []) 172 | { 173 | Log::debug($message, array_merge(self::getContext(), $context)); 174 | } 175 | 176 | // Query logging methods 177 | public static function logSlowQuery(string $sql, array $bindings, float $time) 178 | { 179 | if ($time > config('logging.slow_query_threshold', 1000)) { 180 | self::warning("Slow query detected", [ 181 | 'sql' => $sql, 182 | 'bindings' => $bindings, 183 | 'execution_time' => $time, 184 | 'category' => 'slow_query' 185 | ]); 186 | } 187 | } 188 | 189 | // Cache operations logging 190 | public static function logCacheOperation(string $operation, string $key, $ttl = null) 191 | { 192 | self::debug("Cache operation: {$operation}", [ 193 | 'operation' => $operation, 194 | 'key' => $key, 195 | 'ttl' => $ttl, 196 | 'category' => 'cache' 197 | ]); 198 | } 199 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Boilerplate Core - User Management & Role-Based Authorization 2 | 3 | A comprehensive Laravel boilerplate built with Domain-Driven Design (DDD) architecture, featuring complete user management and dynamic role-based authorization system with Tailwind CSS and Livewire. 4 | 5 | ## 🎯 Product Overview 6 | 7 | This boilerplate provides a solid foundation for web applications that require sophisticated user management and permission systems. Built as a Minimal Viable Product (MVP), it allows developers to immediately start building their unique features on top of a robust authorization framework. 8 | 9 | ## 🚀 Key Features 10 | 11 | ### Core Architecture 12 | - **Domain-Driven Design (DDD)** structure for User, Role, and Permission domains 13 | - **Actions** for business logic separation 14 | - **Models** for database interactions 15 | - **DataTransferObjects** for validation and data transfer 16 | - Clean, maintainable code following Laravel best practices 17 | 18 | ### User Management System 19 | - Complete CRUD operations for users 20 | - User profile management (self-editing) 21 | - Secure authentication system (login, register, forgot password) 22 | - Email verification 23 | - User status management 24 | 25 | ### Dynamic Role & Permission System 26 | - **Roles Management**: Create, edit, delete roles (Admin, Manager, Editor, etc.) 27 | - **Permissions Management**: Define granular permissions (create-post, edit-user, etc.) 28 | - **Role Assignment**: Assign multiple roles to users 29 | - **Permission Assignment**: Assign permissions to roles 30 | - **Dynamic Authorization**: Real-time permission checking 31 | 32 | ### Security & Authorization 33 | - **Middleware Protection**: Route-level permission checks 34 | - **Blade Directives**: `@can`, `@role` for UI element control 35 | - **Dynamic UI Controls**: Show/hide buttons based on user permissions 36 | - **Secure Password Management**: Hashing, reset functionality 37 | 38 | ### Modern Frontend Stack 39 | - **Tailwind CSS**: Clean, responsive, customizable design 40 | - **Livewire**: Dynamic user experience without page reloads 41 | - **Blade Components**: Reusable UI components (buttons, forms, tables) 42 | - **Alpine.js**: Lightweight JavaScript interactions 43 | 44 | ## 🏗️ Project Structure 45 | 46 | ``` 47 | app/ 48 | ├── Domains/ 49 | │ ├── User/ 50 | │ │ ├── Actions/ 51 | │ │ ├── Models/ 52 | │ │ └── DataTransferObjects/ 53 | │ ├── Role/ 54 | │ │ ├── Actions/ 55 | │ │ ├── Models/ 56 | │ │ └── DataTransferObjects/ 57 | │ └── Permission/ 58 | │ ├── Actions/ 59 | │ ├── Models/ 60 | │ └── DataTransferObjects/ 61 | ├── Http/ 62 | │ ├── Controllers/ 63 | │ ├── Middleware/ 64 | │ └── Livewire/ 65 | └── View/ 66 | └── Components/ 67 | ``` 68 | 69 | ## 🎯 Target Market 70 | 71 | ### Primary Users 72 | - **Individual Developers**: Looking for a solid foundation with user management 73 | - **Development Teams**: Need a proven authorization structure to build upon 74 | - **Startups**: Require rapid development with enterprise-grade security 75 | - **Agencies**: Building multiple client projects with similar auth requirements 76 | 77 | ### Use Cases 78 | - **SaaS Applications**: Multi-tenant systems with role-based access 79 | - **Admin Panels**: Content management systems with different user levels 80 | - **E-commerce Platforms**: Customer and admin role separation 81 | - **Corporate Applications**: Department-based access control 82 | 83 | ## 🛠️ Technology Stack 84 | 85 | - **Backend**: Laravel 11+ (Latest) 86 | - **Frontend**: Tailwind CSS 3+, Livewire 3+, Alpine.js 87 | - **Database**: MySQL/SQLite (configurable) 88 | - **Authentication**: Laravel Sanctum 89 | - **Testing**: PHPUnit, Laravel Dusk 90 | - **Code Quality**: Laravel Pint, PHPStan 91 | 92 | ## 📦 What You Get 93 | 94 | ### Immediate Value 95 | 1. **Production-Ready Auth System**: Complete user management out of the box 96 | 2. **Scalable Architecture**: DDD structure supports complex feature additions 97 | 3. **Security Best Practices**: Properly implemented authorization patterns 98 | 4. **Clean UI Components**: Professional-looking interface ready for customization 99 | 5. **Documentation**: Comprehensive setup and usage guides 100 | 101 | ### Long-term Benefits 102 | - **Time Savings**: Skip months of auth system development 103 | - **Security Confidence**: Battle-tested permission patterns 104 | - **Scalability**: Architecture supports enterprise-level applications 105 | - **Maintainability**: Clean code structure for easy team collaboration 106 | 107 | ## 🚀 Quick Start 108 | 109 | ```bash 110 | # Clone the project 111 | git clone [repository-url] 112 | cd laravel-boilerplate-core 113 | 114 | # Install dependencies 115 | composer install 116 | npm install 117 | 118 | # Setup environment 119 | cp .env.example .env 120 | php artisan key:generate 121 | 122 | # Setup database 123 | php artisan migrate --seed 124 | 125 | # Build assets 126 | npm run build 127 | 128 | # Start development server 129 | php artisan serve 130 | ``` 131 | 132 | ## 📋 Default Credentials 133 | 134 | After seeding, you can login with: 135 | - **Admin**: admin@example.com / password 136 | - **Manager**: manager@example.com / password 137 | - **User**: user@example.com / password 138 | 139 | ## 🔧 Configuration 140 | 141 | ### Environment Variables 142 | ```env 143 | # Database Configuration 144 | DB_CONNECTION=mysql 145 | DB_HOST=127.0.0.1 146 | DB_PORT=3306 147 | DB_DATABASE=laravel_boilerplate 148 | DB_USERNAME=root 149 | DB_PASSWORD= 150 | 151 | # Mail Configuration (for password reset) 152 | MAIL_MAILER=smtp 153 | MAIL_HOST=smtp.mailtrap.io 154 | MAIL_PORT=2525 155 | MAIL_USERNAME=null 156 | MAIL_PASSWORD=null 157 | ``` 158 | 159 | ## 🎨 Customization 160 | 161 | ### Styling 162 | - Modify `tailwind.config.js` for brand colors 163 | - Update Blade components in `resources/views/components/` 164 | - Customize Livewire components in `app/Http/Livewire/` 165 | 166 | ### Business Logic 167 | - Add new permissions in `database/seeders/PermissionSeeder.php` 168 | - Create new roles in `database/seeders/RoleSeeder.php` 169 | - Extend user actions in `app/Domains/User/Actions/` 170 | 171 | ## 🧪 Testing 172 | 173 | ```bash 174 | # Run PHP tests 175 | php artisan test 176 | 177 | # Run frontend tests 178 | npm run test 179 | 180 | # Code quality checks 181 | ./vendor/bin/pint 182 | ./vendor/bin/phpstan analyse 183 | ``` 184 | 185 | ## 📸 Screenshots 186 | 187 | ### Login Page 188 | Modern Login Page 189 | 190 | ### Dashboard 191 | Admin Dashboard 192 | 193 | ### User Management 194 | User Management Interface 195 | 196 | ### Role Management 197 | Role Management System 198 | 199 | ### Profile Settings 200 | Profile Settings Page 201 | 202 | ## 📖 Documentation 203 | 204 | - [Installation Guide](docs/installation.md) 205 | - [Architecture Overview](docs/architecture.md) 206 | - [User Management](docs/user-management.md) 207 | - [Roles & Permissions](docs/roles-permissions.md) 208 | - [Customization Guide](docs/customization.md) 209 | - [API Documentation](docs/api.md) 210 | 211 | ## 🤝 Support 212 | 213 | - **Documentation**: Comprehensive guides and examples 214 | - **Code Comments**: Well-documented codebase 215 | - **Best Practices**: Following Laravel and PHP standards 216 | - **Community**: Active discussion and updates 217 | 218 | ## 📄 License 219 | 220 | This project is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). 221 | 222 | ## 🏆 Features Checklist 223 | 224 | - ✅ User CRUD operations 225 | - ✅ Role & Permission management 226 | - ✅ Dynamic authorization middleware 227 | - ✅ Blade directives for UI control 228 | - ✅ Responsive Tailwind CSS design 229 | - ✅ Livewire dynamic components 230 | - ✅ Secure authentication system 231 | - ✅ Email verification 232 | - ✅ Password reset functionality 233 | - ✅ Database seeders with sample data 234 | - ✅ Comprehensive test coverage 235 | - ✅ Clean DDD architecture 236 | - ✅ Production-ready configuration 237 | 238 | --- 239 | 240 | **Ready to build your next application on a solid foundation? This boilerplate eliminates months of development time while providing enterprise-grade security and scalability.** 241 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'database'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to expire immediately when the browser is closed then you may 31 | | indicate that via the expire_on_close configuration option. 32 | | 33 | */ 34 | 35 | 'lifetime' => (int) env('SESSION_LIFETIME', 120), 36 | 37 | 'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false), 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Session Encryption 42 | |-------------------------------------------------------------------------- 43 | | 44 | | This option allows you to easily specify that all of your session data 45 | | should be encrypted before it's stored. All encryption is performed 46 | | automatically by Laravel and you may use the session like normal. 47 | | 48 | */ 49 | 50 | 'encrypt' => env('SESSION_ENCRYPT', false), 51 | 52 | /* 53 | |-------------------------------------------------------------------------- 54 | | Session File Location 55 | |-------------------------------------------------------------------------- 56 | | 57 | | When utilizing the "file" session driver, the session files are placed 58 | | on disk. The default storage location is defined here; however, you 59 | | are free to provide another location where they should be stored. 60 | | 61 | */ 62 | 63 | 'files' => storage_path('framework/sessions'), 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Session Database Connection 68 | |-------------------------------------------------------------------------- 69 | | 70 | | When using the "database" or "redis" session drivers, you may specify a 71 | | connection that should be used to manage these sessions. This should 72 | | correspond to a connection in your database configuration options. 73 | | 74 | */ 75 | 76 | 'connection' => env('SESSION_CONNECTION'), 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Session Database Table 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When using the "database" session driver, you may specify the table to 84 | | be used to store sessions. Of course, a sensible default is defined 85 | | for you; however, you're welcome to change this to another table. 86 | | 87 | */ 88 | 89 | 'table' => env('SESSION_TABLE', 'sessions'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Session Cache Store 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using one of the framework's cache driven session backends, you may 97 | | define the cache store which should be used to store the session data 98 | | between requests. This must match one of your defined cache stores. 99 | | 100 | | Affects: "dynamodb", "memcached", "redis" 101 | | 102 | */ 103 | 104 | 'store' => env('SESSION_STORE'), 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Session Sweeping Lottery 109 | |-------------------------------------------------------------------------- 110 | | 111 | | Some session drivers must manually sweep their storage location to get 112 | | rid of old sessions from storage. Here are the chances that it will 113 | | happen on a given request. By default, the odds are 2 out of 100. 114 | | 115 | */ 116 | 117 | 'lottery' => [2, 100], 118 | 119 | /* 120 | |-------------------------------------------------------------------------- 121 | | Session Cookie Name 122 | |-------------------------------------------------------------------------- 123 | | 124 | | Here you may change the name of the session cookie that is created by 125 | | the framework. Typically, you should not need to change this value 126 | | since doing so does not grant a meaningful security improvement. 127 | | 128 | */ 129 | 130 | 'cookie' => env( 131 | 'SESSION_COOKIE', 132 | Str::snake((string) env('APP_NAME', 'laravel')).'_session' 133 | ), 134 | 135 | /* 136 | |-------------------------------------------------------------------------- 137 | | Session Cookie Path 138 | |-------------------------------------------------------------------------- 139 | | 140 | | The session cookie path determines the path for which the cookie will 141 | | be regarded as available. Typically, this will be the root path of 142 | | your application, but you're free to change this when necessary. 143 | | 144 | */ 145 | 146 | 'path' => env('SESSION_PATH', '/'), 147 | 148 | /* 149 | |-------------------------------------------------------------------------- 150 | | Session Cookie Domain 151 | |-------------------------------------------------------------------------- 152 | | 153 | | This value determines the domain and subdomains the session cookie is 154 | | available to. By default, the cookie will be available to the root 155 | | domain and all subdomains. Typically, this shouldn't be changed. 156 | | 157 | */ 158 | 159 | 'domain' => env('SESSION_DOMAIN'), 160 | 161 | /* 162 | |-------------------------------------------------------------------------- 163 | | HTTPS Only Cookies 164 | |-------------------------------------------------------------------------- 165 | | 166 | | By setting this option to true, session cookies will only be sent back 167 | | to the server if the browser has a HTTPS connection. This will keep 168 | | the cookie from being sent to you when it can't be done securely. 169 | | 170 | */ 171 | 172 | 'secure' => env('SESSION_SECURE_COOKIE'), 173 | 174 | /* 175 | |-------------------------------------------------------------------------- 176 | | HTTP Access Only 177 | |-------------------------------------------------------------------------- 178 | | 179 | | Setting this value to true will prevent JavaScript from accessing the 180 | | value of the cookie and the cookie will only be accessible through 181 | | the HTTP protocol. It's unlikely you should disable this option. 182 | | 183 | */ 184 | 185 | 'http_only' => env('SESSION_HTTP_ONLY', true), 186 | 187 | /* 188 | |-------------------------------------------------------------------------- 189 | | Same-Site Cookies 190 | |-------------------------------------------------------------------------- 191 | | 192 | | This option determines how your cookies behave when cross-site requests 193 | | take place, and can be used to mitigate CSRF attacks. By default, we 194 | | will set this value to "lax" to permit secure cross-site requests. 195 | | 196 | | See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value 197 | | 198 | | Supported: "lax", "strict", "none", null 199 | | 200 | */ 201 | 202 | 'same_site' => env('SESSION_SAME_SITE', 'lax'), 203 | 204 | /* 205 | |-------------------------------------------------------------------------- 206 | | Partitioned Cookies 207 | |-------------------------------------------------------------------------- 208 | | 209 | | Setting this value to true will tie the cookie to the top-level site for 210 | | a cross-site context. Partitioned cookies are accepted by the browser 211 | | when flagged "secure" and the Same-Site attribute is set to "none". 212 | | 213 | */ 214 | 215 | 'partitioned' => env('SESSION_PARTITIONED_COOKIE', false), 216 | 217 | ]; 218 | -------------------------------------------------------------------------------- /resources/views/livewire/roles/role-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if($showModal) 3 |
4 |
5 |
6 |
7 |

8 | {{ $isEditing ? 'Edit Role' : 'Create Role' }} 9 |

10 | 15 |
16 | 17 |
18 |
19 |
20 | 21 | 24 | @error('name') {{ $message }} @enderror 25 |

Only lowercase letters, numbers, and hyphens allowed

26 |
27 | 28 |
29 | 30 | 33 | @error('display_name') {{ $message }} @enderror 34 |
35 |
36 | 37 |
38 | 39 | 42 | @error('description') {{ $message }} @enderror 43 |
44 | 45 |
46 | 50 |
51 | 52 |
53 | 54 |
55 | @foreach($permissionsByGroup as $group => $permissions) 56 |
57 |
58 |

{{ ucfirst($group) }} Permissions

59 | 67 |
68 |
69 | @foreach($permissions as $permission) 70 | 85 | @endforeach 86 |
87 |
88 | @endforeach 89 |
90 | @error('selectedPermissions') {{ $message }} @enderror 91 |
92 | 93 |
94 | 98 | 105 |
106 |
107 |
108 |
109 |
110 | @endif 111 |
112 | 113 | 120 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Login - {{ config('app.name', 'Laravel Boilerplate') }} 8 | 9 | 33 | 34 | 35 | 36 |
37 |
38 |
39 |
40 |
41 |
42 | 43 |
44 |
45 | 46 |
47 |
48 | 49 | 50 | 51 |
52 |

53 | Welcome Back 54 |

55 |

56 | Sign in to {{ config('app.name', 'Laravel Boilerplate') }} 57 |

58 |
59 | 60 | 61 |
62 | @if ($errors->any()) 63 |
64 |
65 | 66 | 67 | 68 |
69 | @foreach ($errors->all() as $error) 70 |

{{ $error }}

71 | @endforeach 72 |
73 |
74 |
75 | @endif 76 | 77 |
78 | @csrf 79 | 80 | 81 |
82 | 85 |
86 |
87 | 88 | 89 | 90 |
91 | 94 |
95 |
96 | 97 | 98 |
99 | 102 |
103 |
104 | 105 | 106 | 107 |
108 | 111 |
112 |
113 | 114 | 115 |
116 |
117 | 120 | 123 |
124 | 125 | @if (Route::has('password.request')) 126 | 131 | @endif 132 |
133 | 134 | 135 |
136 | 145 |
146 |
147 | 148 | 149 |
150 |
151 |

Demo Accounts

152 |
153 |
154 |

Super Admin

155 |

admin@example.com

156 |

password

157 |
158 |
159 |

Regular User

160 |

user@example.com

161 |

password

162 |
163 |
164 |
165 |
166 |
167 | 168 | 169 |
170 |

171 | © {{ date('Y') }} {{ config('app.name', 'Laravel Boilerplate') }}. All rights reserved. 172 |

173 |
174 |
175 |
176 | 177 | -------------------------------------------------------------------------------- /resources/views/livewire/settings/profile-settings.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 |
5 |

Profile Information

6 |

Update your account's profile information and email address.

7 |
8 |
9 | {{ substr($name ?? '', 0, 2) }} 10 |
11 |
12 | 13 | 14 |
15 | 16 |
17 |
18 |
19 | {{ substr($name ?? '', 0, 2) }} 20 |
21 |
22 |

Profile Avatar

23 |

Upload a new avatar image. JPG, PNG up to 2MB.

24 | 25 |
26 | 32 | 39 | @if($avatar) 40 | {{ $avatar->getClientOriginalName() }} 41 | @endif 42 |
43 | @error('avatar') 44 |

{{ $message }}

45 | @enderror 46 |
47 |
48 |
49 | 50 | 51 |
52 | 53 |
54 | 57 |
58 |
59 | 60 | 61 | 62 |
63 | 70 |
71 | @error('name') 72 |

{{ $message }}

73 | @enderror 74 |
75 | 76 | 77 |
78 | 81 |
82 |
83 | 84 | 85 | 86 |
87 | 94 |
95 | @error('email') 96 |

{{ $message }}

97 | @enderror 98 | @if($email !== $current_email) 99 |

100 | 101 | 102 | 103 | Email verification will be required for the new address. 104 |

105 | @endif 106 |
107 |
108 | 109 | 110 |
111 |

Account Information

112 |
113 |
114 |
115 | 116 | 117 | 118 |
119 |
Member Since
120 |
{{ auth()->user()->created_at->format('M Y') }}
121 |
122 |
123 |
124 | 125 | 126 | 127 |
128 |
Active Roles
129 |
{{ auth()->user()->roles->count() }} assigned
130 |
131 |
132 |
133 | 134 | 135 | 136 |
137 |
Account Status
138 |
{{ auth()->user()->is_active ? 'Active' : 'Inactive' }}
139 |
140 |
141 |
142 | 143 | 144 |
145 |
146 | Last updated {{ auth()->user()->updated_at->diffForHumans() }} 147 |
148 |
149 | 159 | 172 |
173 |
174 |
175 |
176 | --------------------------------------------------------------------------------