48 Commits

Author SHA1 Message Date
f5c059cd08 fix: Add gateway network to nginx for NPM connectivity on restart 2026-03-15 12:56:00 +02:00
21620906dc fix: Add public directory to permission fix for storage:link 2026-03-15 12:16:34 +02:00
14084e172a fix: Add permission fix for .env file in setup.sh 2026-03-15 11:56:17 +02:00
6fe63d70af fix: Add permission fix step before artisan commands in setup.sh 2026-03-15 11:53:46 +02:00
fdbd8f5148 fix: Write port config to project root .env for docker compose 2026-03-15 11:49:40 +02:00
cd6043ed64 fix: Properly set port variables in .env for docker compose port mapping 2026-03-15 11:43:59 +02:00
eb05ec9b31 fix: Remove hardcoded container_name and obsolete version to allow multiple deployments 2026-03-15 11:41:54 +02:00
db0cf0c2c4 Replace docker-compose with docker compose in setup script 2026-03-15 11:37:19 +02:00
a6b1cfe498 Add module generator UI and discovery service documentation 2026-03-15 08:59:53 +02:00
dff2cd752c Add ViteHelper fallback for missing frontend assets 2026-03-15 07:47:59 +02:00
94f4e53860 push 2026-03-15 07:37:23 +02:00
779702ca3f Merge branch 'main' of https://git.radapps.co.za/theradcoza/Laravel-Docker-Dev-Template
Merge new feature. menu management
2026-03-14 09:23:45 +02:00
ed7055edaa feat: Add frontend menu management system with permission filtering 2026-03-13 14:21:43 +02:00
6d2d4ad5ca Update REPO_MANAGEMENT.md 2026-03-13 07:25:47 +00:00
551024cc32 Add REPO_MANAGEMENT.md 2026-03-13 07:24:17 +00:00
1995f58056 Add .dockerignore to exclude node_modules from builds 2026-03-12 10:40:05 +02:00
bcb7997ba0 Fix Filament 403 - add FilamentUser interface and canAccessPanel method 2026-03-12 10:22:49 +02:00
a0a722971d Add seeders to production instructions 2026-03-12 10:05:09 +02:00
754153ed1c pass 2026-03-12 10:00:50 +02:00
a1a0d6a6c3 add user make 2026-03-12 09:53:03 +02:00
1d83a3c830 Add make:admin artisan command for creating admin users 2026-03-12 09:51:00 +02:00
fa4c787beb Fix npm ci to npm install in deployment docs 2026-03-12 09:48:17 +02:00
c39a04315c Fix docblock parse error in RolePermissionSeeder 2026-03-11 09:19:59 +02:00
e380721938 Add central Audit Trail viewer in Filament admin
Features:
- AuditResource with table listing all audit logs
- ViewAudit page showing detailed changes with diff table
- Filters: date range, user, model type, event type
- Search by user name
- Auto-refresh every 60 seconds
- Dark mode support for changes view
- Fixed audits migration with proper schema
- Added audit.view permission (admin only by default)

Files:
- src/app/Models/Audit.php
- src/app/Filament/Resources/AuditResource.php
- src/app/Filament/Resources/AuditResource/Pages/
- src/resources/views/filament/infolists/entries/audit-changes.blade.php
- Updated audits migration with full schema
2026-03-11 09:10:38 +02:00
f903914c2b Add auto-loading of module permissions in RolePermissionSeeder
RolePermissionSeeder now automatically scans app/Modules/*/Permissions.php
files and registers all permissions found. No manual registration required.

- Added loadModulePermissions() method to scan module directories
- Changed givePermissionTo() to syncPermissions() for idempotency
- Updated Modules README to document auto-loading
- Updated CLAUDE.md to reflect auto-loading behavior
2026-03-11 08:42:06 +02:00
2b153f1759 Upgrade make:module command with full ServiceProvider structure
Enhanced make:module command:
- Added --model flag for creating model + migration + Filament resource
- Added --api flag for including API routes
- Added --no-filament flag to skip Filament resource
- Creates full ServiceProvider structure with auto-registration
- Creates Config, Permissions, Routes, Views, Tests
- Module migrations stored in module folder
- Filament resources stored in module folder
- Auto-registers ServiceProvider in bootstrap/providers.php

Also added:
- ModuleAuditable trait for audit trail support
- Updated Modules README to document new command options
2026-03-11 08:12:54 +02:00
ac16dbc153 Add AI agent cross-references to docs/modules.md and docs/filament-admin.md 2026-03-11 08:01:27 +02:00
12027d9e98 Add CLAUDE.md - AI agent instructions for module development
Created comprehensive anti-hallucination documentation:
- EXACT file templates with full code examples
- Precise naming conventions (PascalCase, snake_case, kebab-case)
- Step-by-step module creation checklist
- Common mistakes to avoid section
- Filament form/table component reference
- Debugging commands and troubleshooting
- Updated AI_CONTEXT.md and README.md to reference CLAUDE.md
2026-03-11 07:59:39 +02:00
e4c7d09109 Add User Management features (Users, Roles, Permissions)
Added Filament Resources:
- UserResource: Enhanced with role assignment, password confirmation
- RoleResource: Manage roles with permission assignment
- PermissionResource: Manage individual permissions

Features:
- Users can be assigned multiple roles
- Roles can be assigned multiple permissions
- Color-coded badges for roles/permissions
- Filter users by role
- Prevent deletion of admin role
- User Management navigation group
2026-03-11 07:48:43 +02:00
cf6079d58c Redirect landing to login, add registration toggle
Changes:
- Landing page (/) now redirects to /login
- Added 'Enable User Registration' setting (off by default)
- Created CheckRegistrationEnabled middleware
- Registration routes blocked when setting is disabled
- Admin can toggle registration in Settings > System
2026-03-11 07:43:25 +02:00
4b2ff91ac4 Add global site settings view composer with database fallback
Implemented view composer in AppServiceProvider to share site settings across all views:
- Loads site name, logo, colors (primary/secondary/accent), and description from Setting model
- Falls back to config/defaults if database unavailable (prevents errors during migrations)
- Made siteSettings available to all Blade templates

Updated layouts and components to use dynamic settings:
- app.blade.php and guest.blade.php now use siteSettings for
2026-03-11 07:37:27 +02:00
e274d41f19 Fix seeder to actually create admin user
Two issues fixed:
1. Changed create() to firstOrCreate() - makes seeder idempotent
   (can run multiple times without 'already exists' errors)

2. Seeder now CREATES admin user instead of just assigning role
   to existing user. Previous code assumed user existed.

Admin credentials:
- Email: admin@example.com
- Password: password
2026-03-11 07:18:12 +02:00
2ff7a24736 Add frontend asset build to setup scripts
Added Step 11 to both setup.bat and setup.sh:
- Run npm install to install dependencies
- Run npm run build to compile Vite assets
- Creates public/build/manifest.json

This fixes the 'Vite manifest not found' error that occurred
when trying to login after fresh setup.

The node container is used for npm commands since the app
container doesn't have Node.js installed.
2026-03-11 06:25:03 +02:00
119eaf1873 Fix MySQL connection and DatabaseSeeder BOM issues
Two critical fixes:

1. DB_PORT was being appended to Laravel .env file
   - Setup script was writing DB_PORT=3307 (external port)
   - Laravel needs internal Docker port (3306)
   - Now ports are commented out in .env (reference only)
   - Docker-compose uses env vars, Laravel uses fixed internal ports

2. DatabaseSeeder.php had UTF-8 BOM (Byte Order Mark)
   - Caused 'Namespace declaration must be first statement' error
   - Removed invisible BOM bytes from file

These fixes ensure:
- MySQL connections work from within Docker network
- Database seeding completes successfully
- Fresh setup works end-to-end
2026-03-11 06:09:36 +02:00
306413ca56 update setup script 2026-03-10 20:33:13 +02:00
b1453ff249 Fix MySQL connection refused - add proper database readiness check
The previous 5-second fixed wait was insufficient for MySQL 8.0 to fully
initialize, causing migrations and seeders to fail with 'Connection refused'.

Changes:
- Replace 'sleep 5' with active connection polling
- Try to connect every second for up to 30 seconds
- Use PHP PDO to test actual database connectivity
- Only proceed when database accepts connections
- Show clear status when database is ready

This ensures migrations and seeders run only after database is fully ready,
preventing 'Connection refused' errors on fresh setup.

Fixes the issue where Laravel loads but shows MySQL connection error.
2026-03-10 20:31:51 +02:00
ac11580eb3 Add automatic port selection to avoid conflicts
Instead of stopping existing processes, setup scripts now automatically
find and use alternative ports if defaults are in use.

Features:
- Automatically detects port conflicts
- Finds next available port (e.g., 8080 -> 8081 -> 8082...)
- Writes custom ports to .env file
- Shows which ports were reassigned
- Displays correct URLs at end of setup
- Zero user interaction needed

Implementation:
- setup.bat: Uses netstat and batch functions to find free ports
- setup.sh: Uses lsof/netstat and bash functions to find free ports
- Ports checked: APP_PORT, MAIL_DASHBOARD_PORT, MAIL_PORT, REDIS_PORT, DB_PORT
- All ports written to src/.env for docker-compose to use

Example output:
  [OK] Port 8080 (Web Server) - Available
  [!] Port 8025 in use - using 8026 for Mailpit Dashboard

  Your app will be at: http://localhost:8080
  Mailpit at: http://localhost:8026

This ensures setup never fails due to port conflicts and doesn't
disrupt existing services.
2026-03-10 20:06:54 +02:00
0d2506f3ef Fix batch script syntax error in port check
Fixed 'was unexpected at this time' error caused by:
- Unescaped parentheses in echo statements
- Removed extra pipe to LISTENING filter (not needed)
- Changed √ symbol to OK for better Windows compatibility
- Escaped all parentheses with ^ character

The port check now works correctly on Windows.
2026-03-10 12:23:29 +02:00
73a4cd8c40 Fix step numbering in setup.sh after port check addition
Steps 6-9 renumbered to 7-10 to account for the port availability check step added earlier in the script.
2026-03-10 12:04:29 +02:00
e7fcaa35e1 Add port availability check to setup scripts
Before starting Docker containers, setup scripts now check if required
ports are available and warn users about conflicts.

Features:
- Checks all required ports: 8080, 8025, 1025, 6379
- Checks database port based on selection (3306 for MySQL, 5432 for PostgreSQL)
- Shows clear status for each port (Available/In Use)
- If conflicts found:
  - Displays warning message
  - Shows helpful commands to find and stop conflicting processes
  - Asks user if they want to continue anyway
  - Exits if user chooses not to continue

Benefits:
- Prevents confusing 'port already in use' errors during container startup
- Provides clear diagnostic information
- Gives users control over how to handle conflicts
- Improves setup experience and reduces frustration

Implementation:
- setup.bat: Uses netstat with findstr for Windows
- setup.sh: Uses lsof and netstat for Linux/Mac compatibility
2026-03-10 11:56:25 +02:00
83131d8432 MAJOR FIX: Use named volume for vendor/ + pre-install in Dockerfile
This solves the Windows/WSL2 performance issue that caused composer install
to timeout after 300 seconds.

Changes:
1. docker-compose.yml:
   - Added vendor_data named volume for app, queue, scheduler services
   - vendor/ now uses fast Docker volume instead of slow bind mount

2. Dockerfile:
   - Pre-install composer dependencies during image build
   - Copy composer.json/lock first, run install, then copy rest of src
   - Runs as devuser to match runtime permissions
   - Dependencies baked into image = truly 'pre-installed'

3. setup.bat & setup.sh:
   - Removed composer install step (now in Dockerfile)
   - Added -T flag to all docker-compose exec commands (fixes Windows TTY hang)
   - Added 3-second wait for container readiness

Benefits:
-  Setup completes in 2-3 minutes (not 10+ minutes)
-  No composer timeout issues
-  Works on Windows/Mac/Linux
-  vendor/ persists in Docker volume (fast)
-  True 'everything pre-installed' experience

Trade-offs:
- vendor/ not visible in Windows filesystem (in Docker volume)
- Need to rebuild image when adding composer packages
- Slightly larger Docker image (~200MB more)

This is the correct approach for a Docker-based development template.
2026-03-10 11:13:51 +02:00
97acc5e8ea CRITICAL FIX: Move composer install after containers start
The previous setup scripts ran 'composer install' in a temporary container
before starting the actual containers. This caused vendor/ directory to be
created inside the temporary container and then deleted, leaving the host
filesystem without dependencies.

Changes:
- setup.bat: Move composer install to Step 4 (after containers start)
- setup.sh: Move composer install to Step 4 (after containers start)
- Use 'docker-compose exec' instead of 'docker-compose run --rm'
- This ensures vendor/ is written to the host filesystem via volume mount
- Added TEST_SETUP.md with comprehensive testing procedures

Now the vendor/ directory will persist correctly on Windows/WSL2 and the
app will load without 'vendor/autoload.php not found' errors.

This was the root cause of the setup not being truly '2-minute ready'.
2026-03-09 18:35:56 +02:00
7af4f1d14a Remove duplicate admin user creation from setup.bat 2026-03-09 11:44:01 +02:00
3fee3917c5 Fix deployment issues: Add db:seed to setup, fix DatabaseSeeder, add production guide
CRITICAL FIXES:
- DatabaseSeeder now calls RolePermissionSeeder to create roles, permissions, and admin user
- setup.sh and setup.bat now run db:seed automatically during setup
- Created PRODUCTION_DEPLOYMENT.md with complete production deployment guide
- Removed duplicate admin user creation from setup scripts

This ensures:
- Admin user (admin@example.com / password) is created automatically
- Roles (admin, editor, viewer) are created during setup
- Permissions are seeded properly
- Production deployments have clear step-by-step instructions
- PHP Redis extension installation documented
- All common deployment issues addressed

The 2-minute setup now truly works out of the box.
2026-03-09 11:42:25 +02:00
ae410ca4da Add complete feature suite: Permissions, Audit Trail, API Auth, Error Tracking, Module System, and Site Settings
- Install spatie/laravel-permission v6.24 with 3 roles (admin, editor, viewer) and 5 base permissions
- Install owen-it/laravel-auditing v14.0 for tracking model changes
- Install laravel/sanctum v4.3 for API token authentication
- Install spatie/laravel-ignition v2.11 and spatie/flare-client-php v1.10 for enhanced error tracking
- Add Module System with make:module artisan command for scaffolding features
- Create Site Settings page in Filament admin for logo, colors, and configuration
- Add comprehensive debugging documentation (DEBUGGING.md, AI_CONTEXT.md updates)
- Create FEATURES.md with complete feature reference
- Update User model with HasRoles and HasApiTokens traits
- Configure Redis cache and OPcache for performance
- Add RolePermissionSeeder with pre-configured roles and permissions
- Update documentation with debugging-first workflow
- All features pre-installed and production-ready
2026-03-09 09:34:10 +02:00
a55fafd3a9 Enable OPcache and Redis caching for performance 2026-03-09 04:02:29 +02:00
1e868b3ac1 Update documentation for hybrid setup approach 2026-03-09 03:52:30 +02:00
c5260e652b Expand .gitignore for Laravel, update README with one-command setup, simplify env configs 2026-03-09 03:48:40 +02:00
214 changed files with 27485 additions and 1830 deletions

34
.dockerignore Normal file
View File

@@ -0,0 +1,34 @@
# Dependencies
src/node_modules
src/vendor
# Git
.git
.gitignore
# IDE
.idea
.vscode
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Build artifacts
src/public/build
src/public/hot
# Testing
src/coverage
# Logs
*.log
src/storage/logs/*
# Cache
src/bootstrap/cache/*
src/storage/framework/cache/*
src/storage/framework/sessions/*
src/storage/framework/views/*

15
.gitignore vendored
View File

@@ -16,10 +16,21 @@ redis_data/
.DS_Store
Thumbs.db
# Laravel (if src is committed)
# Laravel - commit most files, ignore generated/local files
src/.env
src/vendor/
src/node_modules/
src/.env
src/bootstrap/cache/*
!src/bootstrap/cache/.gitignore
src/storage/*.key
src/storage/logs/*
!src/storage/logs/.gitkeep
src/storage/framework/cache/*
!src/storage/framework/cache/.gitignore
src/storage/framework/sessions/*
!src/storage/framework/sessions/.gitignore
src/storage/framework/views/*
!src/storage/framework/views/.gitignore
src/public/hot
src/public/storage
src/public/build

View File

@@ -1,15 +1,38 @@
# AI Assistant Context
> **🚨 CRITICAL: For detailed module development instructions, see [CLAUDE.md](CLAUDE.md)**
> That document contains EXACT file templates, naming conventions, and step-by-step instructions.
This document provides context for AI coding assistants working on projects built with this template.
## Development Workflow Rules
### Git Branching Strategy
**Rule**: The AI agent must create a new Git branch for every new feature, module, or significant change. It should never commit or push directly to the `main` branch.
**Rationale**: This practice is crucial for maintaining a clean and stable main branch, facilitating code reviews, and making it easier for human developers to collaborate and manage the project's history.
**Example Workflow**:
1. `git checkout -b feature/new-company-module`
2. *...perform all work related to the new module...*
3. `git add .`
4. `git commit -m "feat: Create new company module"`
5. *...agent informs the user that the feature is complete on the new branch...*
## Template Overview
This is a **Laravel Docker Development Template** with:
- Docker-based development environment
- Production deployment to Ubuntu 24.04 (no Docker)
- Modular architecture with Filament admin
- Audit trail for all data changes
- Multi-database support (MySQL, PostgreSQL, SQLite)
This is a **ready-to-use Laravel Docker Development Template** with everything pre-installed:
- ✅ Laravel 11 with Breeze authentication (Blade + dark mode)
- ✅ Filament v3.3 admin panel with user management
- ✅ Pest testing framework
- ✅ Laravel Pint code style
- ✅ Docker-based development environment
- ✅ Production deployment to Ubuntu 24.04 (no Docker)
- ✅ Modular architecture
- ✅ Multi-database support (MySQL, PostgreSQL, SQLite)
**Setup time:** 2 minutes - just run `./setup.sh` and everything is ready!
## Technology Stack
@@ -20,12 +43,51 @@ This is a **Laravel Docker Development Template** with:
| **Admin** | Filament 3.x |
| **Database** | MySQL 8 / PostgreSQL 15 / SQLite |
| **Cache/Queue** | Redis |
| **Auth** | Laravel Breeze or Jetstream (Livewire only) |
| **Permissions** | spatie/laravel-permission |
| **Audit** | owen-it/laravel-auditing |
| **Error Tracking** | spatie/laravel-flare + spatie/laravel-ignition |
| **Auth** | Laravel Breeze (Blade + Livewire) - PRE-INSTALLED |
| **Testing** | Pest - PRE-INSTALLED |
| **Permissions** | spatie/laravel-permission - PRE-INSTALLED |
| **Audit** | owen-it/laravel-auditing - PRE-INSTALLED |
| **Error Tracking** | spatie/laravel-flare + spatie/laravel-ignition - PRE-INSTALLED |
| **API Auth** | Laravel Sanctum - PRE-INSTALLED |
| **Code Style** | Laravel Pint |
## 🚨 CRITICAL: Debugging Strategy
**ALWAYS CHECK LOGS FIRST - NEVER GUESS AT SOLUTIONS**
When encountering errors:
### Step 1: Check Laravel Logs
```bash
docker-compose exec app cat storage/logs/laravel.log | grep -A 20 "Error"
```
### Step 2: Identify Root Cause
- Read the full stack trace
- Find the exact file and line number
- Understand what the code is trying to do
### Step 3: Fix and Verify
- Make targeted fix to root cause
- Clear relevant caches
- Test the specific scenario
### Common Commands:
```bash
# View recent errors
docker-compose exec app tail -n 100 storage/logs/laravel.log
# Check container logs
docker-compose logs --tail=50 app
docker-compose logs --tail=50 nginx
# Clear caches after fixes
docker-compose exec app php artisan optimize:clear
docker-compose exec app php artisan permission:cache-reset
```
**See [DEBUGGING.md](DEBUGGING.md) for complete debugging guide.**
## Important: No JavaScript Frameworks
**This template deliberately avoids JavaScript frameworks** (Vue, React, Inertia) to keep debugging simple. All frontend is:
@@ -287,6 +349,7 @@ make restore file=... # Restore database
## Documentation Links
- **[CLAUDE.md](CLAUDE.md)** - 🚨 **AI AGENTS: START HERE** - Exact module templates
- [GETTING_STARTED.md](GETTING_STARTED.md) - Setup walkthrough
- [README.md](README.md) - Overview
- [docs/modules.md](docs/modules.md) - Module system

782
CLAUDE.md Normal file
View File

@@ -0,0 +1,782 @@
# AI Agent Instructions for Laravel Module Development
> **CRITICAL**: This document provides EXACT specifications for building modules in this Laravel template.
> Follow these instructions PRECISELY. Do NOT deviate, guess, or improvise.
> When in doubt, READ THE EXISTING CODE before making changes.
---
## 🚨 BEFORE YOU START - MANDATORY STEPS
### 1. Always Check Existing Patterns First
```bash
# List existing modules to see patterns
ls -la src/app/Modules/
# Read an existing module's structure
find src/app/Modules/[ExistingModule]/ -type f -name "*.php"
```
### 2. Always Check Logs After Errors
```bash
docker-compose exec app tail -n 100 storage/logs/laravel.log
```
### 3. Never Guess at Solutions
- If you encounter an error, READ the full stack trace
- Find the EXACT file and line number causing the issue
- Understand what the code is trying to do before fixing
---
## 📁 PROJECT STRUCTURE - EXACT PATHS
```
Laravel-Docker-Dev-Template/
├── src/ # ← ALL Laravel code goes here
│ ├── app/
│ │ ├── Filament/
│ │ │ ├── Pages/
│ │ │ │ └── Settings.php # Site settings page
│ │ │ └── Resources/ # Core Filament resources
│ │ │ ├── UserResource.php
│ │ │ ├── RoleResource.php
│ │ │ └── PermissionResource.php
│ │ ├── Http/
│ │ │ ├── Controllers/
│ │ │ └── Middleware/
│ │ ├── Models/
│ │ │ ├── User.php
│ │ │ └── Setting.php
│ │ ├── Modules/ # ← ALL modules go here
│ │ │ └── [ModuleName]/ # ← Each module is a folder
│ │ ├── Providers/
│ │ │ └── AppServiceProvider.php
│ │ └── Traits/
│ │ └── ModuleAuditable.php
│ ├── bootstrap/
│ │ └── app.php # Middleware registration
│ ├── config/
│ ├── database/
│ │ ├── migrations/
│ │ └── seeders/
│ │ ├── DatabaseSeeder.php
│ │ └── RolePermissionSeeder.php
│ ├── resources/
│ │ └── views/
│ │ ├── layouts/
│ │ │ ├── app.blade.php # Authenticated layout
│ │ │ └── guest.blade.php # Guest layout
│ │ └── components/
│ └── routes/
│ ├── web.php
│ ├── api.php
│ └── auth.php
├── docker-compose.yml
├── setup.bat # Windows setup
└── setup.sh # Linux/Mac setup
```
---
## 🔧 MODULE STRUCTURE - EXACT SPECIFICATION
When creating a module named `[ModuleName]` (e.g., `StockManagement`):
```
src/app/Modules/[ModuleName]/
├── Config/
│ └── [module_name].php # snake_case filename
├── Database/
│ ├── Migrations/
│ │ └── YYYY_MM_DD_HHMMSS_create_[table_name]_table.php
│ └── Seeders/
│ └── [ModuleName]Seeder.php
├── Filament/
│ └── Resources/
│ ├── [ModelName]Resource.php
│ └── [ModelName]Resource/
│ └── Pages/
│ ├── List[ModelName]s.php
│ ├── Create[ModelName].php
│ └── Edit[ModelName].php
├── Http/
│ ├── Controllers/
│ │ └── [ModuleName]Controller.php
│ ├── Middleware/
│ └── Requests/
│ └── [ModelName]Request.php
├── Models/
│ └── [ModelName].php
├── Policies/
│ └── [ModelName]Policy.php
├── Services/
│ └── [ModelName]Service.php
├── Routes/
│ ├── web.php
│ └── api.php
├── Resources/
│ └── views/
│ ├── index.blade.php
│ └── layouts/
│ └── module.blade.php
├── Permissions.php
└── [ModuleName]ServiceProvider.php
```
---
## 📝 EXACT FILE TEMPLATES
### 1. Service Provider (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/[ModuleName]ServiceProvider.php`
```php
<?php
namespace App\Modules\[ModuleName];
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
class [ModuleName]ServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->mergeConfigFrom(
__DIR__ . '/Config/[module_name].php',
'[module_name]'
);
}
public function boot(): void
{
$this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
$this->loadViewsFrom(__DIR__ . '/Resources/views', '[module-slug]');
$this->registerRoutes();
}
protected function registerRoutes(): void
{
Route::middleware(['web', 'auth'])
->prefix('[module-slug]')
->name('[module-slug].')
->group(__DIR__ . '/Routes/web.php');
if (file_exists(__DIR__ . '/Routes/api.php')) {
Route::middleware(['api', 'auth:sanctum'])
->prefix('api/[module-slug]')
->name('api.[module-slug].')
->group(__DIR__ . '/Routes/api.php');
}
}
}
```
**NAMING RULES**:
- `[ModuleName]` = PascalCase (e.g., `StockManagement`)
- `[module_name]` = snake_case (e.g., `stock_management`)
- `[module-slug]` = kebab-case (e.g., `stock-management`)
### 2. Config File (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/Config/[module_name].php`
```php
<?php
return [
'name' => '[Module Display Name]',
'slug' => '[module-slug]',
'version' => '1.0.0',
'audit' => [
'enabled' => true,
'strategy' => 'all', // 'all', 'include', 'exclude', 'none'
'include' => [],
'exclude' => [],
],
];
```
### 3. Model (REQUIRED for data modules)
**File**: `src/app/Modules/[ModuleName]/Models/[ModelName].php`
```php
<?php
namespace App\Modules\[ModuleName]\Models;
use App\Traits\ModuleAuditable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
class [ModelName] extends Model implements Auditable
{
use HasFactory, ModuleAuditable;
protected $fillable = [
// List ALL fields that can be mass-assigned
];
protected $casts = [
// Type casts for fields
];
// Define relationships here
}
```
### 4. Migration (REQUIRED for data modules)
**File**: `src/app/Modules/[ModuleName]/Database/Migrations/YYYY_MM_DD_HHMMSS_create_[table_name]_table.php`
```php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('[table_name]', function (Blueprint $table) {
$table->id();
// Define ALL columns here
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('[table_name]');
}
};
```
### 5. Permissions (REQUIRED) - AUTO-LOADED
**File**: `src/app/Modules/[ModuleName]/Permissions.php`
```php
<?php
return [
'[module_name].view' => 'View [Module Name]',
'[module_name].create' => 'Create [Module Name] records',
'[module_name].edit' => 'Edit [Module Name] records',
'[module_name].delete' => 'Delete [Module Name] records',
];
```
> **✅ AUTO-LOADED**: `RolePermissionSeeder` automatically scans all `app/Modules/*/Permissions.php`
> files and registers them. Just run `php artisan db:seed --class=RolePermissionSeeder`.
### 6. Filament Resource (REQUIRED for admin)
**File**: `src/app/Modules/[ModuleName]/Filament/Resources/[ModelName]Resource.php`
```php
<?php
namespace App\Modules\[ModuleName]\Filament\Resources;
use App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource\Pages;
use App\Modules\[ModuleName]\Models\[ModelName];
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class [ModelName]Resource extends Resource
{
protected static ?string $model = [ModelName]::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = '[Module Display Name]';
protected static ?int $navigationSort = 1;
public static function canAccess(): bool
{
return auth()->user()?->can('[module_name].view') ?? false;
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('[Model Name] Details')
->schema([
// Add form fields here
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
// Add table columns here
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\List[ModelName]s::route('/'),
'create' => Pages\Create[ModelName]::route('/create'),
'edit' => Pages\Edit[ModelName]::route('/{record}/edit'),
];
}
}
```
### 7. Filament Resource Pages (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/Filament/Resources/[ModelName]Resource/Pages/List[ModelName]s.php`
```php
<?php
namespace App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource\Pages;
use App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class List[ModelName]s extends ListRecords
{
protected static string $resource = [ModelName]Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
```
**File**: `src/app/Modules/[ModuleName]/Filament/Resources/[ModelName]Resource/Pages/Create[ModelName].php`
```php
<?php
namespace App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource\Pages;
use App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource;
use Filament\Resources\Pages\CreateRecord;
class Create[ModelName] extends CreateRecord
{
protected static string $resource = [ModelName]Resource::class;
}
```
**File**: `src/app/Modules/[ModuleName]/Filament/Resources/[ModelName]Resource/Pages/Edit[ModelName].php`
```php
<?php
namespace App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource\Pages;
use App\Modules\[ModuleName]\Filament\Resources\[ModelName]Resource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class Edit[ModelName] extends EditRecord
{
protected static string $resource = [ModelName]Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
```
### 8. Routes (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/Routes/web.php`
```php
<?php
use App\Modules\[ModuleName]\Http\Controllers\[ModuleName]Controller;
use Illuminate\Support\Facades\Route;
Route::get('/', [[ModuleName]Controller::class, 'index'])->name('index');
```
**File**: `src/app/Modules/[ModuleName]/Routes/api.php` (if API needed)
```php
<?php
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->group(function () {
// API routes here
});
```
### 9. Controller (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/Http/Controllers/[ModuleName]Controller.php`
```php
<?php
namespace App\Modules\[ModuleName]\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class [ModuleName]Controller extends Controller
{
public function index()
{
$this->authorize('[module_name].view');
return view('[module-slug]::index');
}
}
```
### 10. Index View (REQUIRED)
**File**: `src/app/Modules/[ModuleName]/Resources/views/index.blade.php`
```blade
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('[Module Display Name]') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __('[Module Display Name] content goes here.') }}
</div>
</div>
</div>
</div>
</x-app-layout>
```
---
## ✅ MODULE REGISTRATION
After creating all files, register the module in `src/config/app.php` providers array:
```php
'providers' => ServiceProvider::defaultProviders()->merge([
// ...existing providers...
App\Modules\[ModuleName]\[ModuleName]ServiceProvider::class,
])->toArray(),
```
Or add to `src/bootstrap/providers.php`:
```php
return [
App\Providers\AppServiceProvider::class,
// ...existing providers...
App\Modules\[ModuleName]\[ModuleName]ServiceProvider::class,
];
```
---
## 🔄 AFTER MODULE CREATION - REQUIRED COMMANDS
```bash
# 1. Run migrations
docker-compose exec app php artisan migrate
# 2. Clear all caches
docker-compose exec app php artisan optimize:clear
# 3. Seed permissions (if using permissions)
docker-compose exec app php artisan db:seed --class=RolePermissionSeeder
# 4. Reset permission cache
docker-compose exec app php artisan permission:cache-reset
```
---
## ⚠️ COMMON MISTAKES TO AVOID
### 1. Wrong Namespace
`namespace App\Modules\StockManagement\Models;`
`namespace App\Modules\StockManagement\Models;`
The namespace MUST match the folder structure EXACTLY.
### 2. Wrong View Namespace
`return view('stockmanagement::index');`
`return view('StockManagement::index');`
`return view('stock-management::index');`
View namespace is ALWAYS kebab-case.
### 3. Wrong Permission Names
`'StockManagement.view'`
`'stock-management.view'`
`'stock_management.view'`
Permissions are ALWAYS snake_case.
### 4. Forgetting to Register Provider
The module WILL NOT LOAD if you forget to add its ServiceProvider.
### 5. Wrong Import Paths
`use App\Models\Product;`
`use App\Modules\StockManagement\Models\Product;`
Module models are in the MODULE namespace, not the core App namespace.
### 6. Missing Fillable Array
❌ Empty `$fillable` array causes mass-assignment errors
✅ List ALL fields that should be mass-assignable
### 7. Forgetting to Run Migrations
Always run `php artisan migrate` after creating migrations.
---
## 🎨 FILAMENT FORM FIELD REFERENCE
```php
// Text
Forms\Components\TextInput::make('name')
->required()
->maxLength(255);
// Email
Forms\Components\TextInput::make('email')
->email()
->required();
// Password
Forms\Components\TextInput::make('password')
->password()
->required();
// Textarea
Forms\Components\Textarea::make('description')
->rows(3);
// Select
Forms\Components\Select::make('status')
->options([
'active' => 'Active',
'inactive' => 'Inactive',
])
->required();
// Checkbox
Forms\Components\Toggle::make('is_active')
->default(true);
// Date
Forms\Components\DatePicker::make('date');
// DateTime
Forms\Components\DateTimePicker::make('published_at');
// Number
Forms\Components\TextInput::make('price')
->numeric()
->prefix('$');
// File Upload
Forms\Components\FileUpload::make('image')
->image()
->directory('uploads');
// Relationship Select
Forms\Components\Select::make('category_id')
->relationship('category', 'name')
->searchable()
->preload();
```
---
## 📊 FILAMENT TABLE COLUMN REFERENCE
```php
// Text
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable();
// Badge
Tables\Columns\TextColumn::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'active' => 'success',
'inactive' => 'danger',
default => 'gray',
});
// Boolean Icon
Tables\Columns\IconColumn::make('is_active')
->boolean();
// Image
Tables\Columns\ImageColumn::make('avatar')
->circular();
// Date
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable();
// Money
Tables\Columns\TextColumn::make('price')
->money('USD');
```
---
## 🔐 EXISTING CORE RESOURCES
### User Management (already exists in template)
- `src/app/Filament/Resources/UserResource.php` - User CRUD with role assignment
- `src/app/Filament/Resources/RoleResource.php` - Role CRUD with permissions
- `src/app/Filament/Resources/PermissionResource.php` - Permission CRUD
### Settings (already exists)
- `src/app/Filament/Pages/Settings.php` - Site settings (name, logo, colors, registration toggle)
- `src/app/Models/Setting.php` - Settings model with get/set helpers
### Authentication (pre-installed)
- Laravel Breeze with Blade templates
- Login: `/login`
- Register: `/register` (controlled by enable_registration setting)
- Admin: `/admin`
---
## 🧪 TESTING MODULES
Create tests in `src/tests/Feature/Modules/[ModuleName]/`:
```php
<?php
namespace Tests\Feature\Modules\[ModuleName];
use App\Models\User;
use App\Modules\[ModuleName]\Models\[ModelName];
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class [ModelName]Test extends TestCase
{
use RefreshDatabase;
public function test_user_can_view_[model_name]s(): void
{
$user = User::factory()->create();
$user->givePermissionTo('[module_name].view');
$this->actingAs($user)
->get('/[module-slug]')
->assertStatus(200);
}
}
```
---
## 📋 CHECKLIST FOR NEW MODULES
Before considering a module complete:
- [ ] ServiceProvider created and registered
- [ ] Config file created
- [ ] Model created with fillable and casts
- [ ] Migration created and run
- [ ] Permissions.php created
- [ ] Filament Resource created with all pages
- [ ] Controller created
- [ ] Routes (web.php and optionally api.php) created
- [ ] Index view created
- [ ] `php artisan migrate` run
- [ ] `php artisan optimize:clear` run
- [ ] `php artisan db:seed --class=RolePermissionSeeder` run
- [ ] Module accessible at `/[module-slug]`
- [ ] Admin panel shows module in navigation
- [ ] CRUD operations work in admin
---
## 🆘 DEBUGGING
### Module Not Loading
```bash
# Check if provider is registered
docker-compose exec app php artisan about
# Clear everything
docker-compose exec app php artisan optimize:clear
```
### Filament Resource Not Showing
```bash
# Clear Filament cache
docker-compose exec app php artisan filament:cache-components
# Check canAccess() method returns true
# Check user has required permission
```
### Permission Denied
```bash
# Reset permission cache
docker-compose exec app php artisan permission:cache-reset
# Verify permissions exist
docker-compose exec app php artisan tinker
>>> \Spatie\Permission\Models\Permission::pluck('name');
```
### View Not Found
```bash
# Verify view namespace (must be kebab-case)
# Check file exists in Resources/views/
```
---
**Remember**: When in doubt, look at existing code in the codebase. The patterns are already established - follow them exactly.

331
DEBUGGING.md Normal file
View File

@@ -0,0 +1,331 @@
# Debugging Strategy
**CRITICAL**: This template includes enhanced error tracking. Always check logs FIRST before guessing at solutions.
## 🚨 Golden Rule: Logs First, Guessing Never
When encountering errors:
### ❌ WRONG Approach:
1. See error message
2. Guess at the cause
3. Try random fixes
4. Waste time
### ✅ CORRECT Approach:
1. **Check Laravel logs immediately**
2. Read the full stack trace
3. Identify the exact file and line
4. Fix the root cause
---
## Error Tracking Suite
This template includes:
- **Spatie Laravel Ignition** v2.11.0 - Enhanced error pages
- **Spatie Flare Client** v1.10.1 - Error tracking
- **Laravel Logs** - Full context and stack traces
---
## How to Debug Errors
### 1. Check Laravel Logs (PRIMARY METHOD)
```bash
# View recent errors
docker-compose exec app tail -n 100 storage/logs/laravel.log
# Search for specific error
docker-compose exec app cat storage/logs/laravel.log | grep "ErrorType"
# Watch logs in real-time
docker-compose exec app tail -f storage/logs/laravel.log
```
**What you'll see:**
- Exact file path and line number
- Full stack trace
- Variable values at time of error
- User context (if logged in)
### 2. Check Container Logs
```bash
# Application logs
docker-compose logs --tail=50 app
# Nginx logs (for 502/504 errors)
docker-compose logs --tail=50 nginx
# All services
docker-compose logs --tail=50
```
### 3. Use Ignition Error Pages (Development)
When `APP_DEBUG=true`, Laravel shows beautiful error pages with:
- Code context (lines around the error)
- Stack trace with clickable frames
- Solution suggestions for common errors
- Request data and environment info
**Access**: Errors automatically show in browser during development
---
## Common Error Patterns
### TypeError: htmlspecialchars() expects string, array given
**Log Location**: `storage/logs/laravel.log`
**What to look for**:
```
htmlspecialchars(): Argument #1 ($string) must be of type string, array given
at /var/www/html/path/to/file.blade.php:LINE
```
**Root Cause**: Blade template trying to echo an array with `{{ }}`
**Fix**: Use proper component or `@json()` directive
---
### 504 Gateway Timeout
**Log Location**:
- `docker-compose logs nginx`
- `storage/logs/laravel.log`
**What to look for**:
```
upstream timed out (110: Operation timed out)
```
**Common Causes**:
- Stale cache after package installation
- Infinite loop in code
- Database query timeout
- Permission cache issues
**Fix**:
```bash
docker-compose exec app php artisan cache:clear
docker-compose exec app php artisan config:clear
docker-compose exec app php artisan view:clear
docker-compose exec app php artisan permission:cache-reset
docker-compose restart app nginx
```
---
### Database Connection Errors
**Log Location**: `storage/logs/laravel.log`
**What to look for**:
```
SQLSTATE[HY000] [2002] Connection refused
```
**Fix**:
```bash
# Check if database is running
docker-compose ps
# Check database logs
docker-compose logs mysql
# Restart database
docker-compose restart mysql
# Wait for database to be ready
docker-compose exec mysql mysqladmin ping -h localhost
```
---
### Redis Connection Errors
**Log Location**: `storage/logs/laravel.log`
**What to look for**:
```
php_network_getaddresses: getaddrinfo for redis failed
```
**Fix**:
```bash
# Check Redis is running
docker-compose ps redis
# Restart Redis
docker-compose restart redis
# Clear config cache
docker-compose exec app php artisan config:clear
```
---
## Debugging Workflow for AI Agents
When a user reports an error, follow this exact sequence:
### Step 1: Get the Full Error
```bash
docker-compose exec app cat storage/logs/laravel.log | grep -A 20 "ErrorType"
```
### Step 2: Identify Root Cause
- Read the stack trace
- Find the originating file and line
- Understand what the code is trying to do
### Step 3: Verify the Fix
- Make the change
- Clear relevant caches
- Test the specific scenario that caused the error
### Step 4: Document
- Explain what was wrong
- Show the fix
- Explain why it works
---
## Cache Clearing Commands
Always clear caches after:
- Installing new packages
- Changing configuration
- Modifying service providers
- Updating permissions/roles
```bash
# Clear all caches
docker-compose exec app php artisan optimize:clear
# Or individually
docker-compose exec app php artisan cache:clear
docker-compose exec app php artisan config:clear
docker-compose exec app php artisan route:clear
docker-compose exec app php artisan view:clear
docker-compose exec app php artisan permission:cache-reset
# Regenerate autoloader
docker-compose exec app composer dump-autoload
```
---
## Performance Debugging
### Slow Page Loads
**Check**:
1. Laravel Debugbar (if installed)
2. Query count and time
3. OPcache status
4. Redis connection
**Commands**:
```bash
# Check OPcache status
docker-compose exec app php -i | grep opcache
# Monitor Redis
docker-compose exec redis redis-cli monitor
# Check query logs
# Enable in config/database.php: 'log_queries' => true
```
---
## Production Error Tracking
For production, consider:
1. **Flare** (https://flareapp.io)
- Add `FLARE_KEY` to `.env`
- Automatic error reporting
- Error grouping and notifications
2. **Sentry** (alternative)
```bash
composer require sentry/sentry-laravel
```
3. **Log Aggregation**
- Papertrail
- Loggly
- CloudWatch
---
## Best Practices
### ✅ DO:
- Check logs before making changes
- Read the full stack trace
- Clear caches after changes
- Test the specific error scenario
- Document the fix
### ❌ DON'T:
- Guess at solutions without checking logs
- Make multiple changes at once
- Skip cache clearing
- Assume the error message tells the whole story
- Leave debugging code in production
---
## Quick Reference
| Error Type | First Check | Quick Fix |
|------------|-------------|-----------|
| TypeError | Laravel logs | Check variable types |
| 504 Timeout | Nginx logs | Clear caches, restart |
| Database | MySQL logs | Check connection, restart DB |
| Redis | Laravel logs | Restart Redis, clear config |
| Permission | Laravel logs | `permission:cache-reset` |
| View | Laravel logs | `view:clear` |
| Route | Laravel logs | `route:clear` |
---
## Log File Locations
| Service | Log Location |
|---------|--------------|
| Laravel | `storage/logs/laravel.log` |
| Nginx | Docker logs: `docker-compose logs nginx` |
| PHP-FPM | Docker logs: `docker-compose logs app` |
| MySQL | Docker logs: `docker-compose logs mysql` |
| Redis | Docker logs: `docker-compose logs redis` |
---
## Emergency Commands
When everything is broken:
```bash
# Nuclear option - reset everything
docker-compose down
docker-compose up -d
docker-compose exec app php artisan optimize:clear
docker-compose exec app composer dump-autoload
docker-compose exec app php artisan migrate:fresh --seed
```
**⚠️ WARNING**: `migrate:fresh` will delete all data!
---
**Remember**: Logs are your friend. Always check them first. 🔍

272
FEATURES.md Normal file
View File

@@ -0,0 +1,272 @@
# Installed Features
This document lists all features installed in this Laravel Docker Development Template.
## ✅ Complete Feature List
### 1. **Permissions & Roles** (spatie/laravel-permission)
- **Version**: 6.24.1
- **Features**:
- Role-based access control
- Pre-configured roles: admin, editor, viewer
- Permission system for granular access
- User model integration with `HasRoles` trait
- **Usage**:
```php
// Assign role
$user->assignRole('admin');
// Check permission
if ($user->can('users.edit')) { }
// Check role
if ($user->hasRole('admin')) { }
```
- **Database Tables**: `roles`, `permissions`, `model_has_roles`, `model_has_permissions`, `role_has_permissions`
---
### 2. **Audit Trail** (owen-it/laravel-auditing)
- **Version**: 14.0.0
- **Features**:
- Track all model changes (create, update, delete)
- Record user who made changes
- Store old and new values
- Audit log with timestamps
- **Usage**:
```php
use OwenIt\Auditing\Contracts\Auditable;
class Product extends Model implements Auditable
{
use \OwenIt\Auditing\Auditable;
}
// View audits
$audits = $product->audits;
```
- **Database Table**: `audits`
---
### 3. **Error Tracking** (spatie/laravel-ignition + spatie/flare-client-php)
- **Versions**:
- spatie/laravel-ignition: 2.11.0
- spatie/flare-client-php: 1.10.1
- spatie/ignition: 1.15.1
- **Features**:
- Beautiful error pages in development
- Stack trace with code context
- Solution suggestions for common errors
- Optional Flare integration for production error tracking
- **Configuration**: Already active in development mode
---
### 4. **API Authentication** (laravel/sanctum)
- **Version**: 4.3.1
- **Features**:
- Token-based API authentication
- SPA authentication
- Mobile app authentication
- API token management
- **Usage**:
```php
// Generate token
$token = $user->createToken('api-token')->plainTextToken;
// In routes/api.php
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
```
- **User Model**: Updated with `HasApiTokens` trait
- **Database Table**: `personal_access_tokens`
---
### 5. **Site Settings**
- **Features**:
- Logo upload
- Color scheme (primary, secondary, accent)
- Site name and description
- Contact email
- Maintenance mode toggle
- **Location**: `/admin/settings`
- **Usage**:
```php
// Get setting
$siteName = Setting::get('site_name', 'Default');
// Set setting
Setting::set('primary_color', '#3b82f6');
```
- **Files**:
- Model: `app/Models/Setting.php`
- Page: `app/Filament/Pages/Settings.php`
- Migration: `database/migrations/2026_03_09_022522_create_settings_table.php`
---
### 6. **Module System**
- **Features**:
- Artisan command to scaffold complete modules
- Auto-generates: Model, Controller, Routes, Views, Migration, Tests, Filament Resource
- Modular architecture for organizing features
- Blade templates with Tailwind CSS
- **Usage**:
```bash
php artisan make:module ProductCatalog
```
- **Documentation**: `app/Modules/README.md`
- **Command**: `app/Console/Commands/MakeModuleCommand.php`
---
### 7. **Filament Admin Panel**
- **Version**: 3.3
- **Features**:
- User management resource
- Site settings page
- Dashboard with widgets
- Form and table builders
- Dark mode support
- **Access**: http://localhost:8080/admin
- **Credentials**: admin@example.com / password
---
### 8. **Laravel Breeze**
- **Version**: 2.3
- **Features**:
- Login, register, password reset
- Email verification
- Profile management
- Blade templates with Tailwind CSS
- Dark mode support
---
### 9. **Pest Testing Framework**
- **Version**: 3.8
- **Features**:
- Modern testing syntax
- Laravel integration
- Example tests included
- Test helpers for permissions and modules
- **Usage**:
```bash
php artisan test
# or
./vendor/bin/pest
```
---
### 10. **Performance Optimizations**
- **OPcache**: Enabled with development-friendly settings
- **Redis**: Configured for cache and queues
- **Volume Mounts**: Optimized with `:cached` flag for WSL2
- **Config**:
- `CACHE_STORE=redis`
- `SESSION_DRIVER=database`
- `QUEUE_CONNECTION=redis`
---
## Pre-Configured Roles & Permissions
### Roles
1. **Admin** - Full access to all features
2. **Editor** - Can view and edit users
3. **Viewer** - Read-only access to users
### Permissions
- `users.view`
- `users.create`
- `users.edit`
- `users.delete`
- `settings.manage`
---
## Database Tables Created
1. `users` - User accounts
2. `sessions` - User sessions
3. `cache` - Cache storage
4. `jobs` - Queue jobs
5. `failed_jobs` - Failed queue jobs
6. `password_reset_tokens` - Password resets
7. `settings` - Site configuration
8. `roles` - User roles
9. `permissions` - Access permissions
10. `model_has_roles` - User-role assignments
11. `model_has_permissions` - User-permission assignments
12. `role_has_permissions` - Role-permission assignments
13. `audits` - Audit trail logs
14. `personal_access_tokens` - API tokens
---
## Access Points
| Feature | URL | Credentials |
|---------|-----|-------------|
| Public Site | http://localhost:8080 | - |
| Admin Panel | http://localhost:8080/admin | admin@example.com / password |
| Site Settings | http://localhost:8080/admin/settings | Admin access required |
| Email Testing | http://localhost:8025 | - |
| API Endpoints | http://localhost:8080/api/* | Requires Sanctum token |
---
## Next Steps
1. **Customize Site Settings** - Set your logo and brand colors
2. **Create Modules** - Use `php artisan make:module` to build features
3. **Assign Roles** - Give users appropriate access levels
4. **Build API** - Create API endpoints with Sanctum authentication
5. **Write Tests** - Add tests for your custom features
6. **Enable Auditing** - Add `Auditable` interface to models you want to track
7. **Deploy** - See production deployment guide in README.md
---
## Documentation
- [GETTING_STARTED.md](GETTING_STARTED.md) - Setup and configuration
- [README.md](README.md) - Overview and commands
- [app/Modules/README.md](src/app/Modules/README.md) - Module system guide
- [AI_CONTEXT.md](AI_CONTEXT.md) - AI assistant context
---
## Package Versions
All packages are installed and configured:
```json
{
"require": {
"php": "^8.2",
"filament/filament": "^3.2",
"laravel/framework": "^11.31",
"laravel/sanctum": "^4.3",
"laravel/tinker": "^2.9",
"owen-it/laravel-auditing": "^14.0",
"spatie/flare-client-php": "^1.10",
"spatie/laravel-ignition": "^2.11",
"spatie/laravel-permission": "^6.24"
},
"require-dev": {
"laravel/breeze": "^2.3",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.2"
}
}
```
---
**Last Updated**: March 9, 2026

View File

@@ -1,112 +1,129 @@
# Getting Started
This guide walks you through setting up a new Laravel project using this template.
This guide walks you through setting up your Laravel development environment using this template.
## Prerequisites
- Docker & Docker Compose
- Git
- Make (optional, but recommended)
## Quick Start (5 minutes)
## Quick Start (2 minutes)
**Everything is pre-installed!** Just clone and run:
```bash
# 1. Clone the template
git clone https://github.com/your-repo/Laravel-Docker-Dev-Template.git my-project
cd my-project
# 2. Copy environment file
cp .env.example .env
# 2. Run setup (MySQL is default)
./setup.sh # Linux/Mac
setup.bat # Windows
# 3. Choose your database and start
make install DB=mysql # or: pgsql, sqlite
# Or choose a different database:
./setup.sh pgsql # PostgreSQL
./setup.sh sqlite # SQLite
# 4. Run setup scripts (interactive)
make setup-tools # Flare, Pint, error pages
make setup-laravel # Auth, Filament, modules, audit trail
# 5. Access your app
# 3. Access your app
# Laravel: http://localhost:8080
# Admin: http://localhost:8080/admin
# Admin: http://localhost:8080/admin (admin@example.com / password)
# Mail: http://localhost:8025
```
**That's it!** You now have a fully working Laravel application with:
- ✅ Authentication (login, register, password reset)
- ✅ Admin panel with user management
- ✅ Testing framework (Pest)
- ✅ Code style (Pint)
- ✅ Email testing (Mailpit)
## What's Pre-Installed
This template comes with everything configured and ready to use:
### Core Framework
- **Laravel 11** - Latest version with all features
- **Laravel Breeze** - Authentication scaffolding (Blade + dark mode)
- **Livewire** - Reactive components without JavaScript
### Admin & Management
- **Filament v3.3** - Full-featured admin panel
- **User Management** - CRUD interface for users
- **Site Settings** - Logo, color scheme, and site configuration
- **Spatie Permissions** - Role-based access control (admin, editor, viewer)
- **Dashboard** - Admin dashboard with widgets
### Security & Tracking
- **Laravel Auditing** - Track all data changes and user actions
- **Laravel Sanctum** - API authentication with tokens
- **Spatie Ignition** - Enhanced error pages and debugging
### Development Tools
- **Pest** - Modern testing framework with elegant syntax
- **Laravel Pint** - Opinionated code style fixer
- **Mailpit** - Email testing tool
- **Module System** - Artisan command to scaffold new features
### Infrastructure
- **Docker** - Containerized development environment
- **MySQL/PostgreSQL/SQLite** - Choose your database
- **Redis** - Caching and queues (OPcache enabled)
- **Queue Workers** - Background job processing (optional)
- **Scheduler** - Task scheduling (optional)
## Step-by-Step Setup
### 1. Clone and Configure
### 1. Clone the Repository
```bash
git clone https://github.com/your-repo/Laravel-Docker-Dev-Template.git my-project
cd my-project
# Remove template git history and start fresh
# Optional: Remove template git history and start fresh
rm -rf .git
git init
git add .
git commit -m "Initial commit"
```
### 2. Choose Database
### 2. Choose Your Database
| Database | Best For | Command |
|----------|----------|---------|
| **MySQL** | Most projects, production parity | `make install DB=mysql` |
| **PostgreSQL** | Advanced features, JSON, full-text search | `make install DB=pgsql` |
| **SQLite** | Simple apps, quick prototyping | `make install DB=sqlite` |
| **MySQL** | Most projects, production parity | `./setup.sh mysql` |
| **PostgreSQL** | Advanced features, JSON, full-text search | `./setup.sh pgsql` |
| **SQLite** | Simple apps, quick prototyping | `./setup.sh sqlite` |
### 3. Install Laravel
### 3. Run Setup Script
```bash
# Start containers and create Laravel project
make install DB=mysql
# This will:
# - Build Docker images
# - Start containers
# - Run composer create-project laravel/laravel
# - Copy appropriate .env file
# - Generate app key
# - Run initial migrations
./setup.sh mysql # Linux/Mac
setup.bat mysql # Windows
```
### 4. Run Setup Scripts
The script will:
- ✅ Configure environment for chosen database
- ✅ Install composer dependencies
- ✅ Build and start Docker containers
- ✅ Run database migrations
- ✅ Create admin user automatically
#### Post-Install Tools
### 4. Start Developing
```bash
make setup-tools
```
Your application is now ready! The setup script created an admin user for you:
Installs:
- ✅ Spatie Ignition (dev error pages)
- ✅ Spatie Flare (production error tracking)
- ✅ Laravel Pint (code style)
- ✅ Custom error pages (404, 500, 503)
- ❓ Laravel Telescope (optional debugging)
**Admin Login:**
- Email: `admin@example.com`
- Password: `password`
#### Laravel Base Setup
**Access Points:**
- Public site: http://localhost:8080
- Admin panel: http://localhost:8080/admin
- Site settings: http://localhost:8080/admin/settings
- Email testing: http://localhost:8025
- API endpoints: http://localhost:8080/api/*
```bash
make setup-laravel
```
Interactive prompts for:
1. **Authentication** - Choose one:
- Breeze + Blade (recommended)
- Breeze + Livewire
- Breeze API only
- Jetstream + Livewire
2. **Filament Admin** - User management dashboard
3. **Audit Trail** - Track all data changes
4. **Module System** - Modular architecture
5. **API (Sanctum)** - Token authentication
6. **Security Middleware** - HTTPS, headers
### 5. Create Your First Module
## Common Commands
```bash
# Shell into container
@@ -196,17 +213,14 @@ my-project/
### Modules
```bash
# Create module
php artisan make:module ModuleName
# Create a complete module with CRUD, views, tests, and Filament resource
php artisan make:module ProductCatalog
# With model
php artisan make:module ModuleName --model=ModelName
# With API
php artisan make:module ModuleName --api
# Without Filament
php artisan make:module ModuleName --no-filament
# This creates:
# - Model, Controller, Routes, Views
# - Migration and Filament Resource
# - Pest tests
# - See app/Modules/README.md for details
```
## Environment Files
@@ -257,6 +271,41 @@ IGNITION_EDITOR=vscode
## Troubleshooting
### 🚨 FIRST STEP: Check Logs
**Always check logs before trying fixes:**
```bash
# Laravel application logs (MOST IMPORTANT)
docker-compose exec app tail -n 100 storage/logs/laravel.log
# Search for specific error
docker-compose exec app cat storage/logs/laravel.log | grep "ErrorType"
# Container logs
docker-compose logs --tail=50 app
docker-compose logs --tail=50 nginx
```
**See [DEBUGGING.md](DEBUGGING.md) for complete debugging guide.**
---
### Application Errors
When you see errors in the browser:
1. **Check Laravel logs** (see above)
2. **Read the full stack trace** - it shows exact file and line
3. **Clear caches** after making changes:
```bash
docker-compose exec app php artisan optimize:clear
docker-compose exec app php artisan permission:cache-reset
```
---
### Container won't start
```bash
@@ -298,20 +347,18 @@ php artisan migrate
## Next Steps
1. **Configure Flare** - Get API key at [flareapp.io](https://flareapp.io)
2. **Create modules** - `php artisan make:module YourFeature`
3. **Add models** - `php artisan make:module YourFeature --model=YourModel`
4. **Write tests** - `make test`
5. **Deploy** - See [Production Deployment](README.md#production-deployment)
1. **Configure Site Settings** - Visit `/admin/settings` to set logo and colors
2. **Set Up Roles** - Assign users to admin/editor/viewer roles in Filament
3. **Create Modules** - `php artisan make:module YourFeature`
4. **Build API** - Use Sanctum tokens for API authentication
5. **Write Tests** - `php artisan test` or `./vendor/bin/pest`
6. **Configure Flare** - Optional: Get API key at [flareapp.io](https://flareapp.io)
7. **Deploy** - See [Production Deployment](README.md#production-deployment)
## Documentation
- [README.md](README.md) - Overview and commands
- [docs/laravel-setup.md](docs/laravel-setup.md) - Detailed setup options
- [docs/modules.md](docs/modules.md) - Module architecture
- [docs/audit-trail.md](docs/audit-trail.md) - Audit configuration
- [docs/filament-admin.md](docs/filament-admin.md) - Admin panel
- [docs/error-logging.md](docs/error-logging.md) - Error tracking
- [docs/queues.md](docs/queues.md) - Background jobs
- [docs/ci-cd.md](docs/ci-cd.md) - CI/CD pipeline
- [docs/backup.md](docs/backup.md) - Database backup
- [DEBUGGING.md](DEBUGGING.md) - **Debugging strategy (READ THIS FIRST)**
- [FEATURES.md](FEATURES.md) - Complete feature reference
- [AI_CONTEXT.md](AI_CONTEXT.md) - Context for AI assistants
- [app/Modules/README.md](src/app/Modules/README.md) - Module system guide

479
PRODUCTION_DEPLOYMENT.md Normal file
View File

@@ -0,0 +1,479 @@
# Production Deployment Guide
**Target**: Ubuntu 24.04 with Apache/Nginx + PHP-FPM (NO Docker)
---
## Prerequisites on Production Server
### 1. Install Required Software
```bash
# Update system
sudo apt update && sudo apt upgrade -y
# Install PHP 8.3+ and extensions
sudo apt install -y php8.3 php8.3-fpm php8.3-cli php8.3-common \
php8.3-mysql php8.3-pgsql php8.3-sqlite3 \
php8.3-redis php8.3-curl php8.3-mbstring php8.3-xml \
php8.3-zip php8.3-bcmath php8.3-gd php8.3-intl
# Install web server (choose one)
sudo apt install -y apache2 # OR nginx
# Install database (choose one)
sudo apt install -y mysql-server # OR postgresql
# Install Redis
sudo apt install -y redis-server
# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# Install Node.js (for frontend assets)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
```
### 2. Verify PHP Extensions
```bash
php -m | grep -E "redis|pdo_mysql|mbstring|xml|curl|zip|bcmath|gd"
```
All should be listed. If not, install missing extensions.
---
## Deployment Steps
### 1. Clone Repository
```bash
cd /var/www
sudo git clone https://your-repo-url.git your-domain.com
cd your-domain.com/src
```
### 2. Set Permissions
```bash
sudo chown -R www-data:www-data /var/www/your-domain.com
sudo chmod -R 775 /var/www/your-domain.com/src/storage
sudo chmod -R 775 /var/www/your-domain.com/src/bootstrap/cache
```
### 3. Install Dependencies
```bash
# Composer dependencies
composer install --no-dev --optimize-autoloader
# Node dependencies and build assets
npm install
npm run build
```
### 4. Configure Environment
```bash
# Copy appropriate .env template
cp .env.mysql .env # or .env.pgsql or .env.sqlite
# Edit .env
nano .env
```
**Required .env settings:**
```env
APP_NAME="Your App Name"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-domain.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_user
DB_PASSWORD=your_password
CACHE_STORE=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=database
SESSION_DOMAIN=.your-domain.com
SESSION_SECURE_COOKIE=true
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-email
MAIL_PASSWORD=your-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@your-domain.com
MAIL_FROM_NAME="${APP_NAME}"
```
### 5. Generate Application Key
```bash
php artisan key:generate --force
```
### 6. Run Migrations and Seeders
```bash
# Run migrations
php artisan migrate --force
# CRITICAL: Run seeders to create roles, permissions, and admin user
php artisan db:seed --force
```
This creates:
- **Admin user**: admin@example.com / password
- **Roles**: admin, editor, viewer
- **Permissions**: users.view, users.create, users.edit, users.delete, settings.manage
### 7. Optimize for Production
```bash
# Cache configuration
php artisan config:cache
# Cache routes
php artisan route:cache
# Cache views
php artisan view:cache
# Optimize autoloader
composer dump-autoload --optimize
```
### 8. Create Storage Link
```bash
php artisan storage:link
```
---
## Web Server Configuration
### Option A: Apache with Virtual Host
Create `/etc/apache2/sites-available/your-domain.com.conf`:
```apache
<VirtualHost *:80>
ServerName your-domain.com
ServerAlias www.your-domain.com
DocumentRoot /var/www/your-domain.com/src/public
<Directory /var/www/your-domain.com/src/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/your-domain.com-error.log
CustomLog ${APACHE_LOG_DIR}/your-domain.com-access.log combined
# PHP-FPM
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
```
Enable site and modules:
```bash
sudo a2enmod rewrite proxy_fcgi setenvif
sudo a2enconf php8.3-fpm
sudo a2ensite your-domain.com.conf
sudo systemctl restart apache2
```
### Option B: Nginx with Server Block
Create `/etc/nginx/sites-available/your-domain.com`:
```nginx
server {
listen 80;
listen [::]:80;
server_name your-domain.com www.your-domain.com;
root /var/www/your-domain.com/src/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
```
Enable site:
```bash
sudo ln -s /etc/nginx/sites-available/your-domain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```
---
## SSL Certificate (Let's Encrypt)
```bash
# Install Certbot
sudo apt install -y certbot python3-certbot-apache # For Apache
# OR
sudo apt install -y certbot python3-certbot-nginx # For Nginx
# Get certificate
sudo certbot --apache -d your-domain.com -d www.your-domain.com # Apache
# OR
sudo certbot --nginx -d your-domain.com -d www.your-domain.com # Nginx
# Auto-renewal is set up automatically
```
---
## Queue Worker Setup (Optional but Recommended)
Create `/etc/systemd/system/laravel-queue.service`:
```ini
[Unit]
Description=Laravel Queue Worker
After=network.target
[Service]
Type=simple
User=www-data
Group=www-data
Restart=always
ExecStart=/usr/bin/php /var/www/your-domain.com/src/artisan queue:work --sleep=3 --tries=3 --max-time=3600
[Install]
WantedBy=multi-user.target
```
Enable and start:
```bash
sudo systemctl enable laravel-queue
sudo systemctl start laravel-queue
sudo systemctl status laravel-queue
```
---
## Scheduler Setup
Add to crontab:
```bash
sudo crontab -e -u www-data
```
Add this line:
```
* * * * * cd /var/www/your-domain.com/src && php artisan schedule:run >> /dev/null 2>&1
```
---
## Post-Deployment Checklist
- [ ] PHP Redis extension installed: `php -m | grep redis`
- [ ] Database migrations run: `php artisan migrate --force`
- [ ] **Database seeded**: `php artisan db:seed --force` ✅ CRITICAL
- [ ] Storage permissions set: `chmod -R 775 storage bootstrap/cache`
- [ ] Storage link created: `php artisan storage:link`
- [ ] Config cached: `php artisan config:cache`
- [ ] Routes cached: `php artisan route:cache`
- [ ] Views cached: `php artisan view:cache`
- [ ] SSL certificate installed
- [ ] Queue worker running (if using queues)
- [ ] Scheduler configured (if using scheduled tasks)
- [ ] Admin user created and can login at `/admin`
- [ ] `.env` has `APP_DEBUG=false` and `APP_ENV=production`
---
## Access Your Application
- **Public Site**: https://your-domain.com
- **Admin Panel**: https://your-domain.com/admin
- **Admin Login**: admin@example.com / password
**⚠️ IMPORTANT**: Change the default admin password immediately after first login!
---
## Troubleshooting
### 500 Error - Check Logs
```bash
# Laravel logs
tail -f /var/www/your-domain.com/src/storage/logs/laravel.log
# Apache logs
sudo tail -f /var/log/apache2/your-domain.com-error.log
# Nginx logs
sudo tail -f /var/log/nginx/error.log
# PHP-FPM logs
sudo tail -f /var/log/php8.3-fpm.log
```
### Class "Redis" not found
```bash
# Install PHP Redis extension
sudo apt install php8.3-redis
# Restart PHP-FPM
sudo systemctl restart php8.3-fpm
# Restart web server
sudo systemctl restart apache2 # or nginx
```
### 419 Page Expired (CSRF)
Check `.env`:
```env
SESSION_DOMAIN=.your-domain.com
SESSION_SECURE_COOKIE=true
APP_URL=https://your-domain.com
```
Clear cache:
```bash
php artisan config:clear
php artisan cache:clear
```
### Roles Don't Exist
```bash
# Run the seeder
php artisan db:seed --class=RolePermissionSeeder
# Or run all seeders
php artisan db:seed --force
```
### Permission Denied Errors
```bash
sudo chown -R www-data:www-data /var/www/your-domain.com
sudo chmod -R 775 /var/www/your-domain.com/src/storage
sudo chmod -R 775 /var/www/your-domain.com/src/bootstrap/cache
```
---
## Updating the Application
```bash
cd /var/www/your-domain.com
# Pull latest code
sudo -u www-data git pull
# Update dependencies
cd src
composer install --no-dev --optimize-autoloader
npm install && npm run build
# Run migrations
php artisan migrate --force
# Clear and recache
php artisan config:clear
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
# Restart queue worker
sudo systemctl restart laravel-queue
# Restart web server
sudo systemctl restart apache2 # or nginx
```
---
## Security Recommendations
1. **Change default admin password** immediately
2. **Set up firewall**: `sudo ufw enable && sudo ufw allow 80,443/tcp`
3. **Disable directory listing** in web server config
4. **Keep system updated**: `sudo apt update && sudo apt upgrade`
5. **Use strong database passwords**
6. **Enable fail2ban**: `sudo apt install fail2ban`
7. **Regular backups** of database and uploaded files
8. **Monitor logs** for suspicious activity
---
## Backup Strategy
### Database Backup
```bash
# MySQL
mysqldump -u username -p database_name > backup_$(date +%Y%m%d).sql
# PostgreSQL
pg_dump -U username database_name > backup_$(date +%Y%m%d).sql
```
### Files Backup
```bash
# Backup storage directory
tar -czf storage_backup_$(date +%Y%m%d).tar.gz /var/www/your-domain.com/src/storage
```
### Automated Backups
Add to crontab:
```bash
0 2 * * * /path/to/backup-script.sh
```
---
**Remember**: The template is designed for quick local development with Docker. Production deployment requires proper server setup and security hardening.

131
README.md
View File

@@ -4,7 +4,8 @@ A comprehensive Laravel development environment with Docker for local developmen
> **New here?** Start with [GETTING_STARTED.md](GETTING_STARTED.md) for a step-by-step setup guide.
>
> **AI Assistant?** See [AI_CONTEXT.md](AI_CONTEXT.md) for project context and conventions.
> **AI Assistant?** See [CLAUDE.md](CLAUDE.md) for EXACT module templates and step-by-step instructions.
> Also see [AI_CONTEXT.md](AI_CONTEXT.md) for project context and conventions.
## Architecture Overview
@@ -74,6 +75,8 @@ A comprehensive Laravel development environment with Docker for local developmen
│ ├── laravel-setup.md # Laravel setup guide
│ ├── filament-admin.md # Admin panel docs
│ ├── modules.md # Modular architecture guide
│ ├── module-generator.md # Admin UI module generator
│ ├── menu-management.md # Frontend menu system
│ ├── audit-trail.md # Audit trail docs
│ ├── site-settings.md # Appearance settings
│ ├── testing.md # Pest testing guide
@@ -101,60 +104,90 @@ This template supports three database engines via Docker Compose profiles:
### Prerequisites
- Docker & Docker Compose
- Make (optional, for convenience commands)
### Setup
### One-Command Setup
1. **Clone the repository**
```bash
# Clone the repository
git clone <repo-url> my-laravel-app
cd my-laravel-app
# Run setup script (MySQL is default)
./setup.sh # Linux/Mac
setup.bat # Windows
# Or specify database:
./setup.sh mysql # MySQL (default)
./setup.sh pgsql # PostgreSQL
./setup.sh sqlite # SQLite
```
**That's it!** The script will:
- ✅ Configure environment for your database
- ✅ Install composer dependencies
- ✅ Build and start Docker containers
- ✅ Run migrations
- ✅ Create admin user (admin@example.com / password)
**Everything is pre-installed:**
- ✅ Laravel 11 with Breeze authentication
- ✅ Filament admin panel with user management
- ✅ Pest testing framework
- ✅ Laravel Pint code style
- ✅ Queue workers & scheduler (optional)
**Access your app:**
- Laravel App: http://localhost:8080
- Admin Panel: http://localhost:8080/admin
- Mailpit: http://localhost:8025
**Admin Login:**
Interactive (prompts for name and password)
php artisan make:admin admin@example.com
### Manual Setup (Alternative)
If you prefer manual control:
1. **Clone and configure**
```bash
git clone <repo-url> my-laravel-app
cd my-laravel-app
```
2. **Copy environment file**
2. **Build containers**
```bash
cp .env.example .env
```
3. **Install Laravel with your preferred database**
```bash
# With MySQL (default)
make install DB=mysql
# With PostgreSQL
make install DB=pgsql
# With SQLite
make install DB=sqlite
# Or without Make:
docker-compose build
docker-compose --profile mysql run --rm app composer create-project laravel/laravel .
cp src/.env.mysql src/.env
```
4. **Start the development environment**
3. **Install Laravel**
```bash
# Start with your chosen database
make up DB=mysql # or pgsql, sqlite
# Or: docker-compose --profile mysql up -d
docker-compose --profile mysql run --rm app composer create-project laravel/laravel:^11.0 /tmp/new
docker-compose --profile mysql run --rm app sh -c "cp -r /tmp/new/. /var/www/html/ && rm -rf /tmp/new"
```
5. **Access your application**
- Laravel App: http://localhost:8080
- Mailpit: http://localhost:8025
6. **Run setup scripts**
4. **Configure environment**
```bash
# Install Flare, Pint, error pages
make setup-tools
# Configure auth, API, middleware (interactive)
make setup-laravel
# Or run both
make setup-all
cp src/.env.mysql src/.env # For MySQL
# OR
cp src/.env.pgsql src/.env # For PostgreSQL
# OR
cp src/.env.sqlite src/.env # For SQLite
```
5. **Start containers**
```bash
docker-compose --profile mysql up -d
```
6. **Run migrations**
```bash
docker-compose exec app php artisan migrate --force
```
7. **Run setup scripts (optional)**
```bash
docker-compose exec app bash scripts/laravel-setup.sh
```
### Common Commands
@@ -177,6 +210,20 @@ This template supports three database engines via Docker Compose profiles:
| `make setup-laravel` | Configure auth, API, middleware |
| `make setup-all` | Run both setup scripts |
### Frontend Assets (Vite)
Build frontend CSS/JS assets:
```bash
# Build assets for production
docker-compose run --rm node npm run build
# Or run Vite dev server (hot reload)
docker-compose --profile frontend up -d
```
> **Note:** The template includes a resilient fallback - if assets aren't built, basic styling is provided and a development warning is shown. This prevents the `ViteManifestNotFoundException` error from breaking the app.
## Laravel Setup (Auth, API, Middleware)
After installing Laravel, run the interactive setup:
@@ -346,7 +393,9 @@ See [docs/laravel-setup.md](docs/laravel-setup.md) for detailed configuration.
# Edit .env with your settings
php artisan key:generate
php artisan migrate
npm ci && npm run build
npm install && npm run build
php artisan db:seed
php artisan make:admin user@domain.com
```
2. **Configure Nginx**

2
REPO_MANAGEMENT.md Normal file
View File

@@ -0,0 +1,2 @@
Commits must be againsts the module being currently worked on.
Commits must be to a branch that has the exact same name as the module being worked on.

View File

@@ -0,0 +1,16 @@
# Template Improvement Suggestions
This document contains suggestions for improving the template based on recurring development issues.
## 1. Mandatory Module Settings Page
**Rule**: When creating a new module, the AI agent must always create a corresponding settings page within the admin panel.
**Minimum Requirements**: This settings page must, at a minimum, allow an administrator to configure which user roles have Create, Read, Update, and Delete (CRUD) permissions for that module.
**Rationale**: This has been a recurring issue. Automating the creation of a permission management UI for each module makes the template more robust, secure, and user-friendly out-of-the-box. It prevents situations where new modules are added without any way for an admin to control access to them.
**Example Implementation**:
- When a `Blog` module is created, a `Blog Settings` page should also be created.
- This page should contain a form with checkboxes or a multi-select dropdown for each CRUD permission (`blog.view`, `blog.create`, `blog.edit`, `blog.delete`).
- An administrator can then select which roles (e.g., 'admin', 'editor', 'viewer') are granted each of these permissions.

420
TEST_SETUP.md Normal file
View File

@@ -0,0 +1,420 @@
# Testing the 2-Minute Setup
This document verifies that the Laravel Docker Dev Template works as advertised.
---
## Test 1: Fresh Local Setup (Docker)
### Prerequisites
- Docker Desktop running
- Git installed
- No existing containers from this project
### Steps
```bash
# 1. Clone to a fresh directory
cd /tmp # or C:\temp on Windows
git clone https://git.radapps.co.za/theradcoza/Laravel-Docker-Dev-Template.git test-setup
cd test-setup
# 2. Run setup (should take ~2 minutes)
./setup.sh mysql # or setup.bat mysql on Windows
# 3. Verify containers are running
docker-compose ps
```
**Expected Output:**
- `app` container: Up
- `nginx` container: Up
- `mysql` container: Up
- `redis` container: Up
- `mailpit` container: Up
### Verification Checklist
**Database:**
```bash
docker-compose exec app php artisan tinker
```
```php
// Check admin user exists
App\Models\User::where('email', 'admin@example.com')->exists(); // Should return: true
// Check roles exist
Spatie\Permission\Models\Role::count(); // Should return: 3
// Check permissions exist
Spatie\Permission\Models\Permission::count(); // Should return: 5
// Check admin has admin role
$admin = App\Models\User::where('email', 'admin@example.com')->first();
$admin->hasRole('admin'); // Should return: true
exit
```
**Web Access:**
1. Visit http://localhost:8080 - Should show Laravel welcome page
2. Visit http://localhost:8080/admin - Should show Filament login
3. Login with:
- Email: admin@example.com
- Password: password
4. Should successfully login and see admin dashboard
5. Should see "Users" menu item
6. Should see "Settings" menu item
**Settings Page:**
1. Click "Settings" in admin panel
2. Should load without errors
3. Should show form fields:
- Site Name
- Site Logo (file upload)
- Primary Color
- Secondary Color
- Accent Color
- Site Description
- Contact Email
- Maintenance Mode (toggle)
4. Try saving - should show success notification
**Users Management:**
1. Click "Users" in admin panel
2. Should see admin user in list
3. Click "New User"
4. Create test user
5. Should save successfully
**Mailpit:**
1. Visit http://localhost:8025
2. Should show Mailpit interface
3. Send a test email (e.g., password reset)
4. Email should appear in Mailpit
### Success Criteria
✅ Setup completes in under 3 minutes
✅ All containers start successfully
✅ Admin user exists with correct credentials
✅ 3 roles created (admin, editor, viewer)
✅ 5 permissions created
✅ Admin login works
✅ Settings page loads and saves
✅ Users management works
✅ No 500 errors
✅ No 419 CSRF errors
✅ No "Class Redis not found" errors
---
## Test 2: Production Deployment Simulation
### Prerequisites
- Ubuntu 24.04 server (or VM)
- Root or sudo access
- Clean database
### Steps
Follow `PRODUCTION_DEPLOYMENT.md` exactly:
```bash
# 1. Install PHP and extensions
sudo apt update
sudo apt install -y php8.3 php8.3-fpm php8.3-cli php8.3-mysql \
php8.3-redis php8.3-curl php8.3-mbstring php8.3-xml \
php8.3-zip php8.3-bcmath php8.3-gd
# 2. Verify Redis extension
php -m | grep redis # Should output: redis
# 3. Clone repo
cd /var/www
sudo git clone https://git.radapps.co.za/theradcoza/Laravel-Docker-Dev-Template.git test-app
cd test-app/src
# 4. Install dependencies
composer install --no-dev --optimize-autoloader
npm install && npm run build
# 5. Configure environment
cp .env.mysql .env
nano .env # Set database credentials, APP_URL, etc.
# 6. Generate key
php artisan key:generate --force
# 7. Run migrations
php artisan migrate --force
# 8. CRITICAL: Run seeders
php artisan db:seed --force
# 9. Set permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
# 10. Create storage link
php artisan storage:link
# 11. Cache config
php artisan config:cache
php artisan route:cache
php artisan view:cache
```
### Verification
```bash
# Check admin user exists
php artisan tinker
```
```php
App\Models\User::where('email', 'admin@example.com')->exists(); // true
exit
```
**Configure web server** (Apache or Nginx) per `PRODUCTION_DEPLOYMENT.md`
**Test web access:**
1. Visit https://your-domain.com
2. Visit https://your-domain.com/admin
3. Login with admin@example.com / password
4. Should work without errors
### Success Criteria
✅ PHP Redis extension installed
✅ Migrations run successfully
✅ Seeders run successfully
✅ Admin user created
✅ Roles and permissions created
✅ No "Class Redis not found" errors
✅ No 419 CSRF errors
✅ Admin login works
✅ Settings page works
✅ No 500 errors
---
## Test 3: Common Error Scenarios
### Scenario 1: Missing Redis Extension
**Simulate:**
```bash
# On production server, DON'T install php-redis
composer install
php artisan migrate
```
**Expected:**
- Should fail with clear error message
- `PRODUCTION_DEPLOYMENT.md` should have solution
**Fix:**
```bash
sudo apt install php8.3-redis
sudo systemctl restart php8.3-fpm
```
### Scenario 2: Forgot to Run Seeders
**Simulate:**
```bash
php artisan migrate --force
# Skip: php artisan db:seed --force
```
**Expected:**
- Admin user doesn't exist
- Roles don't exist
- Can't login
**Fix:**
```bash
php artisan db:seed --force
```
### Scenario 3: Permission Issues
**Simulate:**
```bash
# Wrong permissions on storage
sudo chmod -R 755 storage
```
**Expected:**
- 500 errors
- Can't write logs
**Fix:**
```bash
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
```
---
## Automated Test Script
Create `test-setup.sh`:
```bash
#!/bin/bash
echo "🧪 Testing Laravel Docker Dev Template Setup..."
echo ""
# Test 1: Check containers
echo "✓ Checking containers..."
if ! docker-compose ps | grep -q "Up"; then
echo "❌ Containers not running"
exit 1
fi
echo "✅ Containers running"
# Test 2: Check admin user
echo "✓ Checking admin user..."
ADMIN_EXISTS=$(docker-compose exec -T app php artisan tinker --execute="echo App\Models\User::where('email', 'admin@example.com')->exists() ? 'true' : 'false';")
if [[ ! "$ADMIN_EXISTS" =~ "true" ]]; then
echo "❌ Admin user not found"
exit 1
fi
echo "✅ Admin user exists"
# Test 3: Check roles
echo "✓ Checking roles..."
ROLE_COUNT=$(docker-compose exec -T app php artisan tinker --execute="echo Spatie\Permission\Models\Role::count();")
if [[ ! "$ROLE_COUNT" =~ "3" ]]; then
echo "❌ Expected 3 roles, found: $ROLE_COUNT"
exit 1
fi
echo "✅ 3 roles created"
# Test 4: Check permissions
echo "✓ Checking permissions..."
PERM_COUNT=$(docker-compose exec -T app php artisan tinker --execute="echo Spatie\Permission\Models\Permission::count();")
if [[ ! "$PERM_COUNT" =~ "5" ]]; then
echo "❌ Expected 5 permissions, found: $PERM_COUNT"
exit 1
fi
echo "✅ 5 permissions created"
# Test 5: Check admin has admin role
echo "✓ Checking admin role assignment..."
HAS_ROLE=$(docker-compose exec -T app php artisan tinker --execute="echo App\Models\User::where('email', 'admin@example.com')->first()->hasRole('admin') ? 'true' : 'false';")
if [[ ! "$HAS_ROLE" =~ "true" ]]; then
echo "❌ Admin user doesn't have admin role"
exit 1
fi
echo "✅ Admin has admin role"
# Test 6: Check web access
echo "✓ Checking web access..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080)
if [ "$HTTP_CODE" != "200" ]; then
echo "❌ Web server not responding (HTTP $HTTP_CODE)"
exit 1
fi
echo "✅ Web server responding"
# Test 7: Check admin panel
echo "✓ Checking admin panel..."
ADMIN_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/admin)
if [ "$ADMIN_CODE" != "200" ]; then
echo "❌ Admin panel not responding (HTTP $ADMIN_CODE)"
exit 1
fi
echo "✅ Admin panel responding"
echo ""
echo "🎉 All tests passed!"
echo ""
echo "Admin Login:"
echo " URL: http://localhost:8080/admin"
echo " Email: admin@example.com"
echo " Password: password"
```
Make executable:
```bash
chmod +x test-setup.sh
```
Run:
```bash
./test-setup.sh
```
---
## Quick Test (30 seconds)
If you just want to verify the basics work:
```bash
# After running setup.sh
docker-compose exec app php artisan tinker --execute="
echo 'Admin exists: ' . (App\Models\User::where('email', 'admin@example.com')->exists() ? 'YES' : 'NO') . PHP_EOL;
echo 'Roles count: ' . Spatie\Permission\Models\Role::count() . PHP_EOL;
echo 'Permissions count: ' . Spatie\Permission\Models\Permission::count() . PHP_EOL;
echo 'Admin has role: ' . (App\Models\User::where('email', 'admin@example.com')->first()->hasRole('admin') ? 'YES' : 'NO') . PHP_EOL;
"
```
**Expected output:**
```
Admin exists: YES
Roles count: 3
Permissions count: 5
Admin has role: YES
```
Then visit http://localhost:8080/admin and login.
---
## Reporting Issues
If any test fails:
1. **Capture logs:**
```bash
docker-compose logs app > app-logs.txt
docker-compose exec app cat storage/logs/laravel.log > laravel-logs.txt
```
2. **Capture database state:**
```bash
docker-compose exec app php artisan tinker --execute="
echo 'Users: ' . App\Models\User::count() . PHP_EOL;
echo 'Roles: ' . Spatie\Permission\Models\Role::count() . PHP_EOL;
echo 'Permissions: ' . Spatie\Permission\Models\Permission::count() . PHP_EOL;
" > db-state.txt
```
3. **Report with:**
- Which test failed
- Error messages
- Log files
- Steps to reproduce
---
## Success Metrics
The template is considered "working correctly" if:
- ✅ Fresh setup completes in under 3 minutes
- ✅ Zero manual intervention required
- ✅ Admin user auto-created with correct credentials
- ✅ All roles and permissions seeded
- ✅ Admin panel accessible immediately
- ✅ Settings page works without errors
- ✅ No Redis errors
- ✅ No CSRF errors
- ✅ Production deployment follows clear guide
- ✅ All common errors documented with solutions

View File

@@ -36,7 +36,7 @@ composer install --no-dev --optimize-autoloader --no-interaction
# Install and build frontend assets
echo "[4/9] Installing Node dependencies..."
npm ci --production=false
npm install
echo "[5/9] Building frontend assets..."
npm run build

View File

@@ -1,4 +1,3 @@
version: '3.8'
services:
# PHP-FPM Application Server
@@ -6,13 +5,12 @@ services:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: laravel_app
restart: unless-stopped
working_dir: /var/www/html
volumes:
- ./src:/var/www/html
- ./src:/var/www/html:cached
- vendor_data:/var/www/html/vendor
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
- sqlite_data:/var/www/html/database
networks:
- laravel_network
depends_on:
@@ -21,15 +19,15 @@ services:
# Nginx Web Server
nginx:
image: nginx:alpine
container_name: laravel_nginx
restart: unless-stopped
ports:
- "${APP_PORT:-8080}:80"
volumes:
- ./src:/var/www/html
- ./src:/var/www/html:cached
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laravel_network
- gateway
depends_on:
- app
@@ -43,7 +41,6 @@ services:
# MySQL Database
mysql:
image: mysql:8.0
container_name: laravel_mysql
restart: unless-stopped
ports:
- "${DB_PORT:-3306}:3306"
@@ -63,7 +60,6 @@ services:
# PostgreSQL Database
pgsql:
image: postgres:16-alpine
container_name: laravel_pgsql
restart: unless-stopped
ports:
- "${DB_PORT:-5432}:5432"
@@ -83,7 +79,6 @@ services:
# This is a dummy service to enable the sqlite profile
sqlite:
image: alpine:latest
container_name: laravel_sqlite_init
volumes:
- ./src/database:/data
command: sh -c "touch /data/database.sqlite && chmod 666 /data/database.sqlite"
@@ -93,7 +88,6 @@ services:
# Redis Cache
redis:
image: redis:alpine
container_name: laravel_redis
restart: unless-stopped
ports:
- "${REDIS_PORT:-6379}:6379"
@@ -105,7 +99,6 @@ services:
# Node.js for frontend assets (Vite/Mix)
node:
image: node:20-alpine
container_name: laravel_node
working_dir: /var/www/html
volumes:
- ./src:/var/www/html
@@ -120,11 +113,11 @@ services:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: laravel_queue
restart: unless-stopped
working_dir: /var/www/html
volumes:
- ./src:/var/www/html
- vendor_data:/var/www/html/vendor
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- laravel_network
@@ -139,11 +132,11 @@ services:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: laravel_scheduler
restart: unless-stopped
working_dir: /var/www/html
volumes:
- ./src:/var/www/html
- vendor_data:/var/www/html/vendor
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- laravel_network
@@ -154,7 +147,6 @@ services:
# Mailpit for local email testing
mailpit:
image: axllent/mailpit
container_name: laravel_mailpit
restart: unless-stopped
ports:
- "${MAIL_PORT:-1025}:1025"
@@ -165,9 +157,11 @@ services:
networks:
laravel_network:
driver: bridge
gateway:
external: true
volumes:
mysql_data:
pgsql_data:
redis_data:
sqlite_data:
vendor_data:

6
docker/.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
node_modules
src/node_modules
src/vendor
.git
.env
*.log

View File

@@ -38,12 +38,27 @@ RUN pecl install redis && docker-php-ext-enable redis
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install Node.js for asset building
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Create system user to run Composer and Artisan commands
RUN useradd -G www-data,root -u 1000 -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
# Copy existing application directory permissions
# Copy composer files first
COPY --chown=devuser:devuser ./src/composer.json ./src/composer.lock /var/www/html/
# Install composer dependencies as devuser
USER devuser
RUN composer install --no-interaction --no-dev --optimize-autoloader --no-scripts
# Switch back to root to copy rest of files
USER root
# Copy existing application directory
COPY --chown=devuser:devuser ./src /var/www/html
# Set proper permissions
@@ -51,6 +66,17 @@ RUN chown -R devuser:www-data /var/www/html \
&& chmod -R 775 /var/www/html/storage 2>/dev/null || true \
&& chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true
# Build frontend assets (if package.json exists)
RUN if [ -f "package.json" ]; then \
npm ci --ignore-scripts && \
npm run build && \
rm -rf node_modules; \
fi
# Run post-install scripts
USER devuser
RUN composer run-script post-autoload-dump 2>/dev/null || true
USER devuser
EXPOSE 9000

View File

@@ -10,6 +10,12 @@ display_errors = On
display_startup_errors = On
error_reporting = E_ALL
; Opcache settings (disabled for development for live reloading)
opcache.enable = 0
; Opcache settings - ENABLED for performance (even in dev on Windows/WSL2)
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 256
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 20000
opcache.validate_timestamps = 1
opcache.revalidate_freq = 2
opcache.fast_shutdown = 1

View File

@@ -191,7 +191,7 @@ composer install --no-dev --optimize-autoloader
php artisan migrate --force
# Build assets
npm ci
npm install
npm run build
# Clear caches

View File

@@ -1,5 +1,7 @@
# Filament Admin Panel
> **🤖 AI Agents**: For Filament form/table component syntax, see [CLAUDE.md](../CLAUDE.md#-filament-form-field-reference).
This template includes optional [Filament](https://filamentphp.com/) admin panel setup for user management and administration.
## What is Filament?

130
docs/menu-management.md Normal file
View File

@@ -0,0 +1,130 @@
# Frontend Menu Management
This template includes a dynamic menu management system that allows administrators to create and manage frontend navigation menus through the admin panel.
## Features
- **Dynamic Menus**: Create multiple menus (header, footer, sidebar, etc.)
- **Nested Items**: Support for parent-child menu items (dropdowns)
- **Multiple Link Types**:
- External links (URLs)
- Named routes
- Module links (auto-generates route from module slug)
- **Permission-Based Filtering**: Menu items are automatically filtered based on user permissions
- **Drag & Drop Reordering**: Reorder menu items in the admin panel
## How It Works
### Permission Filtering
Menu items are automatically filtered based on the current user's permissions:
1. **Module Items**: If a menu item links to a module (e.g., `companies`), the user must have `{module}.view` permission (e.g., `companies.view`) to see that item.
2. **Permission Items**: If a menu item has a specific `permission` set, the user must have that exact permission.
3. **Admin Users**: Users with the `admin` role can see all menu items.
4. **Guest Users**: Only see items with no permission or module restrictions.
## Usage
### In Blade Templates
Use the `<x-frontend-menu>` component to render a menu:
```blade
{{-- Desktop navigation --}}
<x-frontend-menu menu="header" />
{{-- Mobile/responsive navigation --}}
<x-frontend-menu-responsive menu="header" />
{{-- By location --}}
<x-frontend-menu menu="footer" />
```
### Programmatic Access
```php
use App\Services\MenuService;
$menuService = app(MenuService::class);
// Get menu items (already filtered for current user)
$items = $menuService->getMenu('header');
// Get available modules for menu items
$modules = $menuService->getAvailableModules();
// Get available routes for menu items
$routes = $menuService->getAvailableRoutes();
```
## Admin Panel
Navigate to **Settings > Menus** in the admin panel to:
1. Create new menus
2. Add/edit/delete menu items
3. Set item types (link, route, module)
4. Configure permissions for each item
5. Reorder items via drag & drop
## Database Structure
### `menus` table
- `id` - Primary key
- `name` - Display name
- `slug` - Unique identifier (used in templates)
- `location` - Optional location hint (header, footer, sidebar)
- `is_active` - Toggle menu visibility
### `menu_items` table
- `id` - Primary key
- `menu_id` - Foreign key to menus
- `parent_id` - For nested items
- `title` - Display text
- `type` - link, route, or module
- `url` - For external links
- `route` - For named routes
- `route_params` - JSON parameters for routes
- `module` - Module slug for permission checking
- `permission` - Specific permission required
- `icon` - Heroicon name
- `target` - _self or _blank
- `order` - Sort order
- `is_active` - Toggle visibility
## Adding Menu Items for New Modules
When creating a new module, add a menu item to link to it:
1. Go to **Settings > Menus** in admin
2. Edit the "Header Navigation" menu
3. Click "New" in the Items section
4. Set:
- **Title**: Your module name
- **Type**: Module
- **Module**: Select your module from dropdown
5. Save
The menu item will automatically:
- Generate the correct URL (`/{module-slug}`)
- Check for `{module}.view` permission
- Hide from users without permission
## Customization
### Custom Menu Component
Copy and modify the default component:
```bash
cp resources/views/components/frontend-menu.blade.php \
resources/views/components/my-custom-menu.blade.php
```
### Styling
The default components use Tailwind CSS classes. Modify the component templates to match your design.

173
docs/module-generator.md Normal file
View File

@@ -0,0 +1,173 @@
# Module Generator (Admin UI)
A visual tool for creating module skeletons through the Filament admin panel.
> **Development Only**: This tool is only available when `APP_ENV=local`.
## Access
Navigate to: **Admin Panel → Development → Module Generator**
URL: `/admin/module-generator`
## Features
- **Visual Form**: Create modules without command line
- **Auto Git Branch**: Optionally creates `module/{name}` branch and commits files
- **Skeleton Only**: Maximum flexibility - creates structure, you add the models
- **Instant Feedback**: Shows generation logs and next steps
## What Gets Created
```
app/Modules/{ModuleName}/
├── Config/{module_name}.php # Module configuration
├── Database/
│ ├── Migrations/ # Empty, add your migrations
│ └── Seeders/ # Empty, add your seeders
├── Filament/Resources/ # Empty, add Filament resources
├── Http/
│ ├── Controllers/{ModuleName}Controller.php
│ ├── Middleware/ # Empty
│ └── Requests/ # Empty
├── Models/ # Empty, add your models
├── Policies/ # Empty, add policies
├── Services/ # Empty, add services
├── Routes/
│ ├── web.php # Basic index route
│ └── api.php # If API option selected
├── Resources/views/
│ └── index.blade.php # Starter view
├── Permissions.php # CRUD permissions
├── {ModuleName}ServiceProvider.php # Auto-registered
└── README.md # Module documentation
```
## Form Options
| Field | Description |
|-------|-------------|
| **Module Name** | PascalCase name (e.g., `Accounting`, `Inventory`) |
| **Description** | Brief description for README and config |
| **Create Git Branch** | Auto-create `module/{name}` branch and commit |
| **Include API Routes** | Add `Routes/api.php` with Sanctum auth |
## Git Integration
When "Create Git Branch" is enabled:
1. **Checks** for uncommitted changes (fails if dirty)
2. **Creates** branch `module/{module-name}`
3. **Generates** all module files
4. **Commits** with message `feat: Add {ModuleName} module skeleton`
5. **Shows** push command: `git push -u origin module/{name}`
### Requirements
- Working directory must be clean (no uncommitted changes)
- Git must be installed in the container
- Repository must be initialized
## After Generation
1. **Run migrations** (if you add any):
```bash
php artisan migrate
```
2. **Seed permissions**:
```bash
php artisan db:seed --class=RolePermissionSeeder
```
3. **Clear caches**:
```bash
php artisan optimize:clear
```
4. **Push branch** (if Git was used):
```bash
git push -u origin module/{name}
```
## Adding Models
After generating the skeleton, add models manually:
```php
// app/Modules/Accounting/Models/Invoice.php
<?php
namespace App\Modules\Accounting\Models;
use App\Traits\ModuleAuditable;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
class Invoice extends Model implements Auditable
{
use ModuleAuditable;
protected $fillable = [
'number',
'customer_id',
'total',
'status',
];
}
```
## Adding Filament Resources
Create admin CRUD in `Filament/Resources/`:
```php
// app/Modules/Accounting/Filament/Resources/InvoiceResource.php
<?php
namespace App\Modules\Accounting\Filament\Resources;
use App\Modules\Accounting\Models\Invoice;
use Filament\Resources\Resource;
// ... standard Filament resource implementation
```
## Comparison: UI vs CLI
| Feature | UI Generator | `make:module` CLI |
|---------|--------------|-------------------|
| Skeleton only | ✅ | ❌ (includes model) |
| Git integration | ✅ Auto-branch | ❌ Manual |
| Model generation | ❌ | ✅ With `--model=` |
| Filament resource | ❌ | ✅ With `--model=` |
| Visual feedback | ✅ | Terminal output |
| Environment | Local only | Any |
**Use UI Generator when**: You need a blank canvas for complex modules with multiple models.
**Use CLI when**: You want a quick single-model module with all files generated.
## Troubleshooting
### "Git working directory has uncommitted changes"
Commit or stash your changes first:
```bash
git add . && git commit -m "WIP"
# or
git stash
```
### Module not showing in admin
Clear caches:
```bash
php artisan optimize:clear
```
### Permissions not working
Re-seed permissions:
```bash
php artisan db:seed --class=RolePermissionSeeder
```

View File

@@ -1,5 +1,8 @@
# Modular Architecture
> **🤖 AI Agents**: For EXACT file templates and copy-paste code, see [CLAUDE.md](../CLAUDE.md).
> This document explains concepts; CLAUDE.md provides strict implementation patterns.
This template uses a modular architecture to organize features into self-contained modules. Each module has its own admin panel, routes, views, and permissions.
## Quick Start

255
setup.bat Normal file
View File

@@ -0,0 +1,255 @@
@echo off
REM Laravel Docker Development Template - Quick Setup (Windows)
REM Everything is pre-installed! This just starts Docker and sets up the database.
REM Usage: setup.bat [mysql|pgsql|sqlite]
setlocal enabledelayedexpansion
set DB=%1
if "%DB%"=="" set DB=mysql
REM Validate database choice
if not "%DB%"=="mysql" if not "%DB%"=="pgsql" if not "%DB%"=="sqlite" (
echo Error: Invalid database '%DB%'
echo Usage: setup.bat [mysql^|pgsql^|sqlite]
echo Example: setup.bat mysql
exit /b 1
)
echo ========================================================
echo Laravel Docker Development Template
echo Quick Setup - Everything Pre-Installed!
echo ========================================================
echo.
echo Setting up with %DB%...
echo.
REM Step 1: Check port availability and auto-assign alternatives
echo Checking port availability...
REM Function to find next available port
REM Usage: call :find_port <start_port> <result_var>
goto :skip_functions
:find_port
set /a port=%~1
:find_port_loop
netstat -ano | findstr ":%port% " >nul 2>&1
if %errorlevel% equ 0 (
set /a port+=1
goto :find_port_loop
)
set %~2=%port%
exit /b 0
:skip_functions
REM Check and assign APP_PORT (Web Server)
netstat -ano | findstr ":8080" >nul 2>&1
if %errorlevel% equ 0 (
call :find_port 8081 APP_PORT
echo [!] Port 8080 in use - using !APP_PORT! for Web Server
) else (
set APP_PORT=8080
echo [OK] Port 8080 ^(Web Server^) - Available
)
REM Check and assign MAIL_DASHBOARD_PORT (Mailpit Dashboard)
netstat -ano | findstr ":8025" >nul 2>&1
if %errorlevel% equ 0 (
call :find_port 8026 MAIL_DASHBOARD_PORT
echo [!] Port 8025 in use - using !MAIL_DASHBOARD_PORT! for Mailpit Dashboard
) else (
set MAIL_DASHBOARD_PORT=8025
echo [OK] Port 8025 ^(Mailpit Dashboard^) - Available
)
REM Check and assign MAIL_PORT (Mailpit SMTP)
netstat -ano | findstr ":1025" >nul 2>&1
if %errorlevel% equ 0 (
call :find_port 1026 MAIL_PORT
echo [!] Port 1025 in use - using !MAIL_PORT! for Mailpit SMTP
) else (
set MAIL_PORT=1025
echo [OK] Port 1025 ^(Mailpit SMTP^) - Available
)
REM Check and assign REDIS_PORT
netstat -ano | findstr ":6379" >nul 2>&1
if %errorlevel% equ 0 (
call :find_port 6380 REDIS_PORT
echo [!] Port 6379 in use - using !REDIS_PORT! for Redis
) else (
set REDIS_PORT=6379
echo [OK] Port 6379 ^(Redis^) - Available
)
REM Check and assign DB_PORT based on database selection
if "%DB%"=="mysql" (
netstat -ano | findstr ":3306" >nul 2>&1
if !errorlevel! equ 0 (
call :find_port 3307 DB_PORT
echo [!] Port 3306 in use - using !DB_PORT! for MySQL
) else (
set DB_PORT=3306
echo [OK] Port 3306 ^(MySQL^) - Available
)
)
if "%DB%"=="pgsql" (
netstat -ano | findstr ":5432" >nul 2>&1
if !errorlevel! equ 0 (
call :find_port 5433 DB_PORT
echo [!] Port 5432 in use - using !DB_PORT! for PostgreSQL
) else (
set DB_PORT=5432
echo [OK] Port 5432 ^(PostgreSQL^) - Available
)
)
echo.
REM Step 2: Configure environment
echo Configuring environment...
if exist "src\.env.%DB%" (
copy /y "src\.env.%DB%" "src\.env" >nul
REM Append port configurations to .env (for reference only, not used by Laravel)
REM Note: DB_PORT is NOT appended - Laravel uses internal Docker port (3306/5432)
REM These are for docker-compose external port mapping only
echo. >> src\.env
echo # Port Configuration ^(auto-assigned by setup^) >> src\.env
echo # APP_PORT=%APP_PORT% >> src\.env
echo # MAIL_DASHBOARD_PORT=%MAIL_DASHBOARD_PORT% >> src\.env
echo # MAIL_PORT=%MAIL_PORT% >> src\.env
echo # REDIS_PORT=%REDIS_PORT% >> src\.env
echo Environment configured for %DB%
) else (
echo ERROR: Template file src\.env.%DB% not found
exit /b 1
)
REM Step 3: Build containers
echo Building Docker containers...
docker-compose build
echo Containers built
echo.
REM Step 4: Start containers
echo Starting Docker containers...
docker-compose --profile %DB% up -d
echo Containers started
echo.
REM Step 5: Wait for app container to be ready
echo Waiting for app container...
timeout /t 3 /nobreak >nul
echo App container ready
echo.
REM Step 6: Wait for database
if "%DB%"=="mysql" (
echo Waiting for MySQL to be ready...
set DB_READY=0
for /L %%i in (1,1,30) do (
docker-compose exec -T app php -r "new PDO('mysql:host=mysql;dbname=laravel', 'laravel', 'secret');" >nul 2>&1
if !errorlevel! equ 0 (
set DB_READY=1
goto :mysql_ready
)
timeout /t 1 /nobreak >nul
)
:mysql_ready
if !DB_READY! equ 1 (
echo MySQL ready
) else (
echo WARNING: MySQL may not be fully ready yet
)
echo.
)
if "%DB%"=="pgsql" (
echo Waiting for PostgreSQL to be ready...
set DB_READY=0
for /L %%i in (1,1,30) do (
docker-compose exec -T app php -r "new PDO('pgsql:host=pgsql;dbname=laravel', 'laravel', 'secret');" >nul 2>&1
if !errorlevel! equ 0 (
set DB_READY=1
goto :pgsql_ready
)
timeout /t 1 /nobreak >nul
)
:pgsql_ready
if !DB_READY! equ 1 (
echo PostgreSQL ready
) else (
echo WARNING: PostgreSQL may not be fully ready yet
)
echo.
)
REM Step 7: Generate app key
echo Generating application key...
docker-compose exec -T app php artisan key:generate --force
echo App key generated
echo.
REM Step 8: Run migrations
echo Running database migrations...
docker-compose exec -T app php artisan migrate --force
echo Migrations completed
echo.
REM Step 9: Seed database
echo Seeding database (roles, permissions, admin user)...
docker-compose exec -T app php artisan db:seed --force
echo Database seeded
echo.
REM Step 10: Create storage link
echo Creating storage symlink...
docker-compose exec -T app php artisan storage:link
echo Storage linked
echo.
REM Step 11: Build frontend assets
echo Building frontend assets...
docker-compose run --rm node npm install >nul 2>&1
docker-compose run --rm node npm run build >nul 2>&1
echo Frontend assets built
echo.
REM Done
echo.
echo ========================================================
echo Setup Complete!
echo ========================================================
echo.
echo Your Laravel application is ready!
echo.
echo Laravel App: http://localhost:%APP_PORT%
echo Admin Panel: http://localhost:%APP_PORT%/admin
echo Mailpit: http://localhost:%MAIL_DASHBOARD_PORT%
echo.
echo Admin Login:
echo Email: admin@example.com
echo Password: password
echo.
echo What's Included:
echo - Laravel 11 with Breeze authentication
echo - Filament admin panel with user management
echo - Pest testing framework
echo - Laravel Pint code style
echo - Queue workers ^& scheduler (optional profiles)
echo.
echo Common Commands:
echo docker-compose exec app php artisan [command]
echo docker-compose exec app composer [command]
echo docker-compose exec app ./vendor/bin/pest
echo docker-compose logs -f app
echo.
echo Stop containers:
echo docker-compose down
echo.
endlocal

237
setup.sh Normal file
View File

@@ -0,0 +1,237 @@
#!/bin/bash
# Laravel Docker Development Template - Quick Setup
# Everything is pre-installed! This just starts Docker and sets up the database.
# Usage: ./setup.sh [mysql|pgsql|sqlite]
set -e
DB=${1:-mysql}
VALID_DBS=("mysql" "pgsql" "sqlite")
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Laravel Docker Development Template ║${NC}"
echo -e "${GREEN}║ Quick Setup - Everything Pre-Installed! ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
# Validate database choice
if [[ ! " ${VALID_DBS[@]} " =~ " ${DB} " ]]; then
echo -e "${RED}Error: Invalid database '${DB}'${NC}"
echo "Usage: ./setup.sh [mysql|pgsql|sqlite]"
echo "Example: ./setup.sh mysql"
exit 1
fi
echo -e "${YELLOW}Setting up with ${DB}...${NC}"
echo ""
# Step 1: Check port availability and auto-assign alternatives
echo -e "${YELLOW}→ Checking port availability...${NC}"
# Function to find next available port
find_port() {
local port=$1
while lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":$port "; do
port=$((port + 1))
done
echo $port
}
# Check and assign APP_PORT (Web Server)
if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":8080 "; then
APP_PORT=$(find_port 8081)
echo -e "${YELLOW}[!] Port 8080 in use - using $APP_PORT for Web Server${NC}"
else
APP_PORT=8080
echo -e "${GREEN}[✓] Port 8080 (Web Server) - Available${NC}"
fi
# Check and assign MAIL_DASHBOARD_PORT (Mailpit Dashboard)
if lsof -Pi :8025 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":8025 "; then
MAIL_DASHBOARD_PORT=$(find_port 8026)
echo -e "${YELLOW}[!] Port 8025 in use - using $MAIL_DASHBOARD_PORT for Mailpit Dashboard${NC}"
else
MAIL_DASHBOARD_PORT=8025
echo -e "${GREEN}[✓] Port 8025 (Mailpit Dashboard) - Available${NC}"
fi
# Check and assign MAIL_PORT (Mailpit SMTP)
if lsof -Pi :1025 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":1025 "; then
MAIL_PORT=$(find_port 1026)
echo -e "${YELLOW}[!] Port 1025 in use - using $MAIL_PORT for Mailpit SMTP${NC}"
else
MAIL_PORT=1025
echo -e "${GREEN}[✓] Port 1025 (Mailpit SMTP) - Available${NC}"
fi
# Check and assign REDIS_PORT
if lsof -Pi :6379 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":6379 "; then
REDIS_PORT=$(find_port 6380)
echo -e "${YELLOW}[!] Port 6379 in use - using $REDIS_PORT for Redis${NC}"
else
REDIS_PORT=6379
echo -e "${GREEN}[✓] Port 6379 (Redis) - Available${NC}"
fi
# Check and assign DB_PORT based on database selection
if [ "$DB" = "mysql" ]; then
if lsof -Pi :3306 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":3306 "; then
DB_PORT=$(find_port 3307)
echo -e "${YELLOW}[!] Port 3306 in use - using $DB_PORT for MySQL${NC}"
else
DB_PORT=3306
echo -e "${GREEN}[✓] Port 3306 (MySQL) - Available${NC}"
fi
elif [ "$DB" = "pgsql" ]; then
if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null 2>&1 || netstat -tuln 2>/dev/null | grep -q ":5432 "; then
DB_PORT=$(find_port 5433)
echo -e "${YELLOW}[!] Port 5432 in use - using $DB_PORT for PostgreSQL${NC}"
else
DB_PORT=5432
echo -e "${GREEN}[✓] Port 5432 (PostgreSQL) - Available${NC}"
fi
fi
echo ""
# Step 2: Configure environment
echo -e "${YELLOW}→ Configuring environment...${NC}"
if [ -f "src/.env.${DB}" ]; then
cp "src/.env.${DB}" "src/.env"
# Create .env in project root for docker compose port mapping
echo "# Docker Compose Port Configuration (auto-assigned by setup)" > .env
echo "APP_PORT=$APP_PORT" >> .env
echo "MAIL_DASHBOARD_PORT=$MAIL_DASHBOARD_PORT" >> .env
echo "MAIL_PORT=$MAIL_PORT" >> .env
echo "REDIS_PORT=$REDIS_PORT" >> .env
if [ -n "$DB_PORT" ]; then
echo "DB_PORT=$DB_PORT" >> .env
fi
echo -e "${GREEN}✓ Environment configured for ${DB}${NC}"
else
echo -e "${RED}✗ Template file src/.env.${DB} not found${NC}"
exit 1
fi
# Step 3: Build containers
echo -e "${YELLOW}→ Building Docker containers...${NC}"
docker compose build
echo -e "${GREEN}✓ Containers built${NC}"
echo ""
# Step 4: Start containers
echo -e "${YELLOW}→ Starting Docker containers...${NC}"
docker compose --profile ${DB} up -d
echo -e "${GREEN}✓ Containers started${NC}"
echo ""
# Step 5: Wait for app container to be ready
echo -e "${YELLOW}→ Waiting for app container...${NC}"
sleep 3
echo -e "${GREEN}✓ App container ready${NC}"
echo ""
# Step 5.5: Fix permissions on storage, bootstrap/cache, public, and .env
echo -e "${YELLOW}→ Setting directory permissions...${NC}"
chmod -R 777 src/storage src/bootstrap/cache src/public 2>/dev/null || true
chmod 666 src/.env 2>/dev/null || true
docker compose exec -T app chmod -R 777 storage bootstrap/cache public 2>/dev/null || true
docker compose exec -T app chmod 666 .env 2>/dev/null || true
echo -e "${GREEN}✓ Permissions set${NC}"
echo ""
# Step 6: Wait for database
if [ "$DB" = "mysql" ]; then
echo -e "${YELLOW}→ Waiting for MySQL to be ready...${NC}"
for i in {1..30}; do
if docker compose exec -T app php -r "new PDO('mysql:host=mysql;dbname=laravel', 'laravel', 'secret');" >/dev/null 2>&1; then
echo -e "${GREEN}✓ MySQL ready${NC}"
break
fi
sleep 1
done
echo ""
elif [ "$DB" = "pgsql" ]; then
echo -e "${YELLOW}→ Waiting for PostgreSQL to be ready...${NC}"
for i in {1..30}; do
if docker compose exec -T app php -r "new PDO('pgsql:host=pgsql;dbname=laravel', 'laravel', 'secret');" >/dev/null 2>&1; then
echo -e "${GREEN}✓ PostgreSQL ready${NC}"
break
fi
sleep 1
done
echo ""
fi
# Step 7: Generate app key
echo -e "${YELLOW}→ Generating application key...${NC}"
docker compose exec app php artisan key:generate --force
echo -e "${GREEN}✓ App key generated${NC}"
echo ""
# Step 8: Run migrations
echo -e "${YELLOW}→ Running database migrations...${NC}"
docker compose exec app php artisan migrate --force
echo -e "${GREEN}✓ Migrations completed${NC}"
echo ""
# Step 9: Seed database (roles, permissions, admin user)
echo -e "${YELLOW}→ Seeding database (roles, permissions, admin user)...${NC}"
docker compose exec app php artisan db:seed --force
echo -e "${GREEN}✓ Database seeded${NC}"
echo ""
# Step 10: Create storage link
echo -e "${YELLOW}→ Creating storage symlink...${NC}"
docker compose exec app php artisan storage:link
echo -e "${GREEN}✓ Storage linked${NC}"
echo ""
# Step 11: Build frontend assets
echo -e "${YELLOW}→ Building frontend assets...${NC}"
docker compose run --rm node npm install >/dev/null 2>&1
docker compose run --rm node npm run build >/dev/null 2>&1
echo -e "${GREEN}✓ Frontend assets built${NC}"
echo ""
# Done!
echo ""
echo -e "${GREEN}╔════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ 🎉 Setup Complete! 🎉 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${GREEN}Your Laravel application is ready!${NC}"
echo ""
echo -e " 📱 Laravel App: ${GREEN}http://localhost:$APP_PORT${NC}"
echo -e " 🔐 Admin Panel: ${GREEN}http://localhost:$APP_PORT/admin${NC}"
echo -e " 📧 Mailpit: ${GREEN}http://localhost:$MAIL_DASHBOARD_PORT${NC}"
echo ""
echo -e "${YELLOW}Admin Login:${NC}"
echo -e " Email: admin@example.com"
echo -e " Password: password"
echo ""
echo -e "${YELLOW}What's Included:${NC}"
echo -e " ✓ Laravel 11 with Breeze authentication"
echo -e " ✓ Filament admin panel with user management"
echo -e " ✓ Pest testing framework"
echo -e " ✓ Laravel Pint code style"
echo -e " ✓ Queue workers & scheduler (optional profiles)"
echo ""
echo -e "${YELLOW}Common Commands:${NC}"
echo -e " docker compose exec app php artisan <command>"
echo -e " docker compose exec app composer <command>"
echo -e " docker compose exec app ./vendor/bin/pest"
echo -e " docker compose logs -f app"
echo ""
echo -e "${YELLOW}Stop containers:${NC}"
echo -e " docker compose down"
echo ""

18
src/.editorconfig Normal file
View File

@@ -0,0 +1,18 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4

View File

@@ -1,25 +1,18 @@
# Laravel Environment Configuration
#
# This template supports multiple databases. Copy the appropriate file:
# - .env.mysql - MySQL configuration
# - .env.pgsql - PostgreSQL configuration
# - .env.sqlite - SQLite configuration
#
# Example: cp .env.mysql .env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost:8080
APP_URL=http://localhost
APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database
# APP_MAINTENANCE_STORE=database
PHP_CLI_SERVER_WORKERS=4
BCRYPT_ROUNDS=12
@@ -28,29 +21,14 @@ LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
# Database: Choose one configuration
# ===================================
# MySQL:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
# PostgreSQL (uncomment and comment MySQL above):
# DB_CONNECTION=pgsql
# DB_HOST=pgsql
# DB_PORT=5432
DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=laravel
# DB_USERNAME=laravel
# DB_PASSWORD=secret
# DB_USERNAME=root
# DB_PASSWORD=
# SQLite (uncomment and comment MySQL above):
# DB_CONNECTION=sqlite
# DB_DATABASE=/var/www/html/database/database.sqlite
SESSION_DRIVER=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
@@ -58,33 +36,31 @@ SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
QUEUE_CONNECTION=database
CACHE_STORE=redis
CACHE_STORE=database
CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_MAILER=log
MAIL_SCHEME=null
MAIL_HOST=127.0.0.1
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
# Error Logging - Flare (https://flareapp.io)
# Get your key at: https://flareapp.io
FLARE_KEY=
# Ignition Settings (Development)
# Themes: light, dark, auto
# Editors: vscode, phpstorm, sublime, atom, textmate
IGNITION_THEME=auto
IGNITION_EDITOR=vscode

View File

@@ -26,7 +26,7 @@ DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
SESSION_DRIVER=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
@@ -37,7 +37,9 @@ FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
CACHE_STORE=redis
CACHE_PREFIX=
CACHE_PREFIX=laravel_cache
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=redis
@@ -53,12 +55,10 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
# Error Logging - Flare (https://flareapp.io)
# Get your key at: https://flareapp.io
FLARE_KEY=
# Ignition Settings (Development)
IGNITION_THEME=auto
IGNITION_EDITOR=vscode

View File

@@ -26,7 +26,7 @@ DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret
SESSION_DRIVER=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
@@ -37,7 +37,9 @@ FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
CACHE_STORE=redis
CACHE_PREFIX=
CACHE_PREFIX=laravel_cache
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=redis
@@ -53,12 +55,10 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
# Error Logging - Flare (https://flareapp.io)
# Get your key at: https://flareapp.io
FLARE_KEY=
# Ignition Settings (Development)
IGNITION_THEME=auto
IGNITION_EDITOR=vscode

View File

@@ -22,7 +22,7 @@ LOG_LEVEL=debug
DB_CONNECTION=sqlite
DB_DATABASE=/var/www/html/database/database.sqlite
SESSION_DRIVER=redis
SESSION_DRIVER=database
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
@@ -33,7 +33,9 @@ FILESYSTEM_DISK=local
QUEUE_CONNECTION=redis
CACHE_STORE=redis
CACHE_PREFIX=
CACHE_PREFIX=laravel_cache
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=redis
@@ -49,12 +51,10 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}"
# Error Logging - Flare (https://flareapp.io)
# Get your key at: https://flareapp.io
FLARE_KEY=
# Ignition Settings (Development)
IGNITION_THEME=auto
IGNITION_EDITOR=vscode

11
src/.gitattributes vendored Normal file
View File

@@ -0,0 +1,11 @@
* text=auto eol=lf
*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore

23
src/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/auth.json
/.fleet
/.idea
/.nova
/.vscode
/.zed

View File

@@ -1,2 +0,0 @@
# This directory will contain your Laravel application
# Run: docker-compose run --rm app composer create-project laravel/laravel .

66
src/README.md Normal file
View File

@@ -0,0 +1,66 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## About Laravel
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, powerful, and provides tools required for large, robust applications.
## Learning Laravel
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
## Laravel Sponsors
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
### Premium Partners
- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[WebReinvent](https://webreinvent.com/)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Jump24](https://jump24.co.uk)**
- **[Redberry](https://redberry.international/laravel/)**
- **[Active Logic](https://activelogic.com)**
- **[byte5](https://byte5.de)**
- **[OP.GG](https://op.gg)**
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class MakeAdminCommand extends Command
{
protected $signature = 'make:admin
{email : The email address for the admin user}
{--name= : The name for the admin user}
{--password= : The password (will prompt if not provided)}';
protected $description = 'Create a new admin user with full permissions';
public function handle(): int
{
$email = $this->argument('email');
$name = $this->option('name') ?? $this->ask('Enter admin name', 'Admin');
$password = $this->option('password') ?? $this->secret('Enter password');
// Validate email
$validator = Validator::make(
['email' => $email],
['email' => 'required|email|unique:users,email']
);
if ($validator->fails()) {
$this->error('Validation failed:');
foreach ($validator->errors()->all() as $error) {
$this->error(" - {$error}");
}
return Command::FAILURE;
}
// Validate password
if (strlen($password) < 8) {
$this->error('Password must be at least 8 characters.');
return Command::FAILURE;
}
// Create user
$user = User::create([
'name' => $name,
'email' => $email,
'password' => Hash::make($password),
'email_verified_at' => now(),
]);
// Assign admin role
$user->assignRole('admin');
$this->info("✅ Admin user created successfully!");
$this->table(
['Field', 'Value'],
[
['Name', $name],
['Email', $email],
['Role', 'admin'],
]
);
$this->newLine();
$this->info("Login at: /admin");
return Command::SUCCESS;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,597 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class MakeModuleCommand extends Command
{
protected $signature = 'make:module
{name : The name of the module (PascalCase)}
{--model= : Create a model with the given name}
{--api : Include API routes}
{--no-filament : Skip Filament resource generation}';
protected $description = 'Create a new module with full structure (ServiceProvider, Config, Routes, Views, Permissions)';
protected string $studlyName;
protected string $kebabName;
protected string $snakeName;
protected string $modulePath;
protected ?string $modelName;
public function handle(): int
{
$name = $this->argument('name');
$this->studlyName = Str::studly($name);
$this->kebabName = Str::kebab($name);
$this->snakeName = Str::snake($name);
$this->modelName = $this->option('model') ? Str::studly($this->option('model')) : null;
$this->modulePath = app_path("Modules/{$this->studlyName}");
if (File::exists($this->modulePath)) {
$this->error("Module {$this->studlyName} already exists!");
return self::FAILURE;
}
$this->info("Creating module: {$this->studlyName}");
$this->newLine();
$this->createDirectoryStructure();
$this->createServiceProvider();
$this->createConfig();
$this->createPermissions();
$this->createController();
$this->createRoutes();
$this->createViews();
if ($this->modelName) {
$this->createModel();
$this->createMigration();
if (!$this->option('no-filament')) {
$this->createFilamentResource();
}
}
$this->createTests();
$this->registerServiceProvider();
$this->newLine();
$this->info("✅ Module {$this->studlyName} created successfully!");
$this->newLine();
$this->warn("Next steps:");
$this->line(" 1. Run migrations: <info>php artisan migrate</info>");
$this->line(" 2. Seed permissions: <info>php artisan db:seed --class=RolePermissionSeeder</info>");
$this->line(" 3. Clear caches: <info>php artisan optimize:clear</info>");
$this->newLine();
$this->line(" Access at:");
$this->line(" - Frontend: <info>/{$this->kebabName}</info>");
if ($this->modelName && !$this->option('no-filament')) {
$this->line(" - Admin: <info>/admin → {$this->studlyName}</info>");
}
if ($this->option('api')) {
$this->line(" - API: <info>/api/{$this->kebabName}</info>");
}
return self::SUCCESS;
}
protected function createDirectoryStructure(): void
{
$directories = [
'',
'/Config',
'/Database/Migrations',
'/Database/Seeders',
'/Filament/Resources',
'/Http/Controllers',
'/Http/Middleware',
'/Http/Requests',
'/Models',
'/Policies',
'/Services',
'/Routes',
'/Resources/views',
];
foreach ($directories as $dir) {
File::makeDirectory("{$this->modulePath}{$dir}", 0755, true);
}
$this->info("✓ Created directory structure");
}
protected function createServiceProvider(): void
{
$stub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName};
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
class {$this->studlyName}ServiceProvider extends ServiceProvider
{
public function register(): void
{
\$this->mergeConfigFrom(
__DIR__ . '/Config/{$this->snakeName}.php',
'{$this->snakeName}'
);
}
public function boot(): void
{
\$this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
\$this->loadViewsFrom(__DIR__ . '/Resources/views', '{$this->kebabName}');
\$this->registerRoutes();
\$this->registerPermissions();
}
protected function registerRoutes(): void
{
Route::middleware(['web', 'auth'])
->prefix('{$this->kebabName}')
->name('{$this->kebabName}.')
->group(__DIR__ . '/Routes/web.php');
if (file_exists(__DIR__ . '/Routes/api.php')) {
Route::middleware(['api', 'auth:sanctum'])
->prefix('api/{$this->kebabName}')
->name('api.{$this->kebabName}.')
->group(__DIR__ . '/Routes/api.php');
}
}
protected function registerPermissions(): void
{
// Permissions are registered via RolePermissionSeeder
// See: Permissions.php in this module
}
}
PHP;
File::put("{$this->modulePath}/{$this->studlyName}ServiceProvider.php", $stub);
$this->info("✓ Created ServiceProvider");
}
protected function createConfig(): void
{
$stub = <<<PHP
<?php
return [
'name' => '{$this->studlyName}',
'slug' => '{$this->kebabName}',
'version' => '1.0.0',
'audit' => [
'enabled' => true,
'strategy' => 'all', // 'all', 'include', 'exclude', 'none'
'include' => [],
'exclude' => [],
],
];
PHP;
File::put("{$this->modulePath}/Config/{$this->snakeName}.php", $stub);
$this->info("✓ Created Config");
}
protected function createPermissions(): void
{
$stub = <<<PHP
<?php
return [
'{$this->snakeName}.view' => 'View {$this->studlyName}',
'{$this->snakeName}.create' => 'Create {$this->studlyName} records',
'{$this->snakeName}.edit' => 'Edit {$this->studlyName} records',
'{$this->snakeName}.delete' => 'Delete {$this->studlyName} records',
];
PHP;
File::put("{$this->modulePath}/Permissions.php", $stub);
$this->info("✓ Created Permissions");
}
protected function createController(): void
{
$stub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class {$this->studlyName}Controller extends Controller
{
public function index()
{
\$this->authorize('{$this->snakeName}.view');
return view('{$this->kebabName}::index');
}
}
PHP;
File::put("{$this->modulePath}/Http/Controllers/{$this->studlyName}Controller.php", $stub);
$this->info("✓ Created Controller");
}
protected function createRoutes(): void
{
// Web routes
$webStub = <<<PHP
<?php
use App\Modules\\{$this->studlyName}\Http\Controllers\\{$this->studlyName}Controller;
use Illuminate\Support\Facades\Route;
Route::get('/', [{$this->studlyName}Controller::class, 'index'])->name('index');
PHP;
File::put("{$this->modulePath}/Routes/web.php", $webStub);
// API routes (if requested)
if ($this->option('api')) {
$apiStub = <<<PHP
<?php
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->group(function () {
// API routes here
});
PHP;
File::put("{$this->modulePath}/Routes/api.php", $apiStub);
}
$this->info("✓ Created Routes" . ($this->option('api') ? ' (web + api)' : ''));
}
protected function createViews(): void
{
$stub = <<<BLADE
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('{$this->studlyName}') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
{{ __('{$this->studlyName} module is working!') }}
</div>
</div>
</div>
</div>
</x-app-layout>
BLADE;
File::put("{$this->modulePath}/Resources/views/index.blade.php", $stub);
$this->info("✓ Created Views");
}
protected function createModel(): void
{
$tableName = Str::snake(Str::plural($this->modelName));
$stub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Models;
use App\Traits\ModuleAuditable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;
class {$this->modelName} extends Model implements Auditable
{
use HasFactory, ModuleAuditable;
protected \$table = '{$tableName}';
protected \$fillable = [
'name',
'description',
];
protected \$casts = [
//
];
}
PHP;
File::put("{$this->modulePath}/Models/{$this->modelName}.php", $stub);
$this->info("✓ Created Model: {$this->modelName}");
}
protected function createMigration(): void
{
$tableName = Str::snake(Str::plural($this->modelName));
$timestamp = date('Y_m_d_His');
$migrationName = "create_{$tableName}_table";
$stub = <<<PHP
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('{$tableName}', function (Blueprint \$table) {
\$table->id();
\$table->string('name');
\$table->text('description')->nullable();
\$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('{$tableName}');
}
};
PHP;
$migrationPath = "{$this->modulePath}/Database/Migrations/{$timestamp}_{$migrationName}.php";
File::put($migrationPath, $stub);
$this->info("✓ Created Migration: {$migrationName}");
}
protected function createFilamentResource(): void
{
$modelClass = "App\\Modules\\{$this->studlyName}\\Models\\{$this->modelName}";
$tableName = Str::snake(Str::plural($this->modelName));
// Create the resource
$resourceStub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Filament\Resources;
use App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource\Pages;
use App\Modules\\{$this->studlyName}\Models\\{$this->modelName};
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class {$this->modelName}Resource extends Resource
{
protected static ?string \$model = {$this->modelName}::class;
protected static ?string \$navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string \$navigationGroup = '{$this->studlyName}';
protected static ?int \$navigationSort = 1;
public static function canAccess(): bool
{
return auth()->user()?->can('{$this->snakeName}.view') ?? false;
}
public static function form(Form \$form): Form
{
return \$form
->schema([
Forms\Components\Section::make('{$this->modelName} Details')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Textarea::make('description')
->rows(3),
]),
]);
}
public static function table(Table \$table): Table
{
return \$table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('description')
->limit(50),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\List{$this->modelName}s::route('/'),
'create' => Pages\Create{$this->modelName}::route('/create'),
'edit' => Pages\Edit{$this->modelName}::route('/{record}/edit'),
];
}
}
PHP;
File::put("{$this->modulePath}/Filament/Resources/{$this->modelName}Resource.php", $resourceStub);
// Create Pages directory
File::makeDirectory("{$this->modulePath}/Filament/Resources/{$this->modelName}Resource/Pages", 0755, true);
// Create List page
$listStub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource\Pages;
use App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class List{$this->modelName}s extends ListRecords
{
protected static string \$resource = {$this->modelName}Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
PHP;
File::put("{$this->modulePath}/Filament/Resources/{$this->modelName}Resource/Pages/List{$this->modelName}s.php", $listStub);
// Create Create page
$createStub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource\Pages;
use App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource;
use Filament\Resources\Pages\CreateRecord;
class Create{$this->modelName} extends CreateRecord
{
protected static string \$resource = {$this->modelName}Resource::class;
}
PHP;
File::put("{$this->modulePath}/Filament/Resources/{$this->modelName}Resource/Pages/Create{$this->modelName}.php", $createStub);
// Create Edit page
$editStub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource\Pages;
use App\Modules\\{$this->studlyName}\Filament\Resources\\{$this->modelName}Resource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class Edit{$this->modelName} extends EditRecord
{
protected static string \$resource = {$this->modelName}Resource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
PHP;
File::put("{$this->modulePath}/Filament/Resources/{$this->modelName}Resource/Pages/Edit{$this->modelName}.php", $editStub);
$this->info("✓ Created Filament Resource: {$this->modelName}Resource");
}
protected function createTests(): void
{
$testPath = base_path("tests/Feature/Modules/{$this->studlyName}");
File::makeDirectory($testPath, 0755, true);
$stub = <<<PHP
<?php
namespace Tests\Feature\Modules\\{$this->studlyName};
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class {$this->studlyName}Test extends TestCase
{
use RefreshDatabase;
public function test_user_can_view_{$this->snakeName}_index(): void
{
\$user = User::factory()->create();
\$user->givePermissionTo('{$this->snakeName}.view');
\$response = \$this->actingAs(\$user)
->get('/{$this->kebabName}');
\$response->assertStatus(200);
}
public function test_unauthorized_user_cannot_view_{$this->snakeName}(): void
{
\$user = User::factory()->create();
\$response = \$this->actingAs(\$user)
->get('/{$this->kebabName}');
\$response->assertStatus(403);
}
}
PHP;
File::put("{$testPath}/{$this->studlyName}Test.php", $stub);
$this->info("✓ Created Tests");
}
protected function registerServiceProvider(): void
{
$providersPath = base_path('bootstrap/providers.php');
if (File::exists($providersPath)) {
$content = File::get($providersPath);
$providerClass = "App\\Modules\\{$this->studlyName}\\{$this->studlyName}ServiceProvider::class";
if (!str_contains($content, $providerClass)) {
// Add the provider before the closing bracket
$content = preg_replace(
'/(\];)/',
" {$providerClass},\n$1",
$content
);
File::put($providersPath, $content);
$this->info("✓ Registered ServiceProvider in bootstrap/providers.php");
}
} else {
$this->warn("⚠ Could not auto-register ServiceProvider. Add manually to config/app.php:");
$this->line(" App\\Modules\\{$this->studlyName}\\{$this->studlyName}ServiceProvider::class");
}
}
}

View File

@@ -0,0 +1,186 @@
<?php
namespace App\Filament\Pages;
use App\Services\ModuleDiscoveryService;
use App\Services\ModuleGeneratorService;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Illuminate\Support\Str;
class ModuleGenerator extends Page implements HasForms
{
use InteractsWithForms;
protected static ?string $navigationIcon = 'heroicon-o-cube';
protected static ?string $navigationLabel = 'Module Generator';
protected static ?string $navigationGroup = 'Development';
protected static ?int $navigationSort = 100;
protected static string $view = 'filament.pages.module-generator';
public ?array $data = [];
public ?array $result = null;
public array $modules = [];
public array $summary = [];
public ?string $expandedModule = null;
public static function canAccess(): bool
{
// Only available in local environment
return app()->environment('local');
}
public static function shouldRegisterNavigation(): bool
{
return app()->environment('local');
}
public function mount(): void
{
$this->form->fill([
'create_git_branch' => true,
'include_api' => false,
]);
$this->loadModules();
}
public function loadModules(): void
{
$discovery = new ModuleDiscoveryService();
$this->modules = $discovery->discoverModules();
$this->summary = $discovery->getModuleSummary();
}
public function toggleModule(string $moduleName): void
{
$this->expandedModule = $this->expandedModule === $moduleName ? null : $moduleName;
}
public function form(Form $form): Form
{
return $form
->schema([
Section::make('Module Details')
->description('Create a new module skeleton with all the necessary folders and files.')
->schema([
TextInput::make('name')
->label('Module Name')
->placeholder('e.g., Accounting, Inventory, HumanResources')
->helperText('Use PascalCase. This will create app/Modules/YourModuleName/')
->required()
->maxLength(50)
->rules(['regex:/^[A-Z][a-zA-Z0-9]*$/'])
->validationMessages([
'regex' => 'Module name must be PascalCase (start with uppercase, letters and numbers only).',
])
->live(onBlur: true)
->afterStateUpdated(fn ($state, callable $set) =>
$set('name', Str::studly($state))
),
Textarea::make('description')
->label('Description')
->placeholder('Brief description of what this module does...')
->rows(2)
->maxLength(255),
]),
Section::make('Options')
->schema([
Toggle::make('create_git_branch')
->label('Create Git Branch')
->helperText('Automatically create and checkout a new branch: module/{module-name}')
->default(true),
Toggle::make('include_api')
->label('Include API Routes')
->helperText('Add Routes/api.php with Sanctum authentication')
->default(false),
])
->columns(2),
Section::make('What Will Be Created')
->schema([
\Filament\Forms\Components\Placeholder::make('structure')
->label('')
->content(fn () => new \Illuminate\Support\HtmlString('
<div class="text-sm text-gray-600 dark:text-gray-400 font-mono bg-gray-50 dark:bg-gray-900 p-4 rounded-lg">
<div class="font-bold mb-2">app/Modules/{ModuleName}/</div>
<div class="ml-4">
├── Config/{module_name}.php<br>
├── Database/Migrations/<br>
├── Database/Seeders/<br>
├── Filament/Resources/<br>
├── Http/Controllers/{ModuleName}Controller.php<br>
├── Http/Middleware/<br>
├── Http/Requests/<br>
├── Models/<br>
├── Policies/<br>
├── Services/<br>
├── Routes/web.php<br>
├── Resources/views/index.blade.php<br>
├── Permissions.php<br>
├── {ModuleName}ServiceProvider.php<br>
└── README.md
</div>
</div>
')),
])
->collapsible()
->collapsed(),
])
->statePath('data');
}
public function generate(): void
{
$data = $this->form->getState();
$service = new ModuleGeneratorService();
$this->result = $service->generate($data['name'], [
'description' => $data['description'] ?? '',
'create_git_branch' => $data['create_git_branch'] ?? true,
'include_api' => $data['include_api'] ?? false,
]);
if ($this->result['success']) {
Notification::make()
->title('Module Created Successfully!')
->body("Module {$this->result['module_name']} has been created.")
->success()
->persistent()
->send();
// Reset form for next module
$this->form->fill([
'name' => '',
'description' => '',
'create_git_branch' => true,
'include_api' => false,
]);
// Reload modules list
$this->loadModules();
} else {
Notification::make()
->title('Module Creation Failed')
->body($this->result['message'])
->danger()
->persistent()
->send();
}
}
public function clearResult(): void
{
$this->result = null;
}
}

View File

@@ -0,0 +1,132 @@
<?php
namespace App\Filament\Pages;
use App\Models\Setting;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
class Settings extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static string $view = 'filament.pages.settings';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 99;
public ?array $data = [];
public function mount(): void
{
$siteName = Setting::get('site_name', config('app.name'));
$siteLogo = Setting::get('site_logo');
$primaryColor = Setting::get('primary_color', '#3b82f6');
$secondaryColor = Setting::get('secondary_color', '#8b5cf6');
$accentColor = Setting::get('accent_color', '#10b981');
$siteDescription = Setting::get('site_description');
$contactEmail = Setting::get('contact_email');
$maintenanceMode = Setting::get('maintenance_mode', false);
$enableRegistration = Setting::get('enable_registration', false);
$this->form->fill([
'site_name' => is_string($siteName) ? $siteName : config('app.name'),
'site_logo' => is_string($siteLogo) || is_null($siteLogo) ? $siteLogo : null,
'primary_color' => is_string($primaryColor) ? $primaryColor : '#3b82f6',
'secondary_color' => is_string($secondaryColor) ? $secondaryColor : '#8b5cf6',
'accent_color' => is_string($accentColor) ? $accentColor : '#10b981',
'site_description' => is_string($siteDescription) || is_null($siteDescription) ? $siteDescription : '',
'contact_email' => is_string($contactEmail) || is_null($contactEmail) ? $contactEmail : '',
'maintenance_mode' => is_bool($maintenanceMode) ? $maintenanceMode : false,
'enable_registration' => is_bool($enableRegistration) ? $enableRegistration : false,
]);
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('General Settings')
->schema([
Forms\Components\TextInput::make('site_name')
->label('Site Name')
->required()
->maxLength(255),
Forms\Components\FileUpload::make('site_logo')
->label('Site Logo')
->image()
->directory('logos')
->visibility('public'),
Forms\Components\Textarea::make('site_description')
->label('Site Description')
->rows(3)
->maxLength(500),
Forms\Components\TextInput::make('contact_email')
->label('Contact Email')
->email()
->maxLength(255),
]),
Forms\Components\Section::make('Color Scheme')
->schema([
Forms\Components\ColorPicker::make('primary_color')
->label('Primary Color'),
Forms\Components\ColorPicker::make('secondary_color')
->label('Secondary Color'),
Forms\Components\ColorPicker::make('accent_color')
->label('Accent Color'),
])
->columns(3),
Forms\Components\Section::make('System')
->schema([
Forms\Components\Toggle::make('enable_registration')
->label('Enable User Registration')
->helperText('Allow new users to register. When disabled, only admins can create users.'),
Forms\Components\Toggle::make('maintenance_mode')
->label('Maintenance Mode')
->helperText('Enable to put the site in maintenance mode'),
]),
])
->statePath('data');
}
protected function getFormActions(): array
{
return [
Action::make('save')
->label('Save Settings')
->submit('save'),
];
}
public function save(): void
{
$data = $this->form->getState();
Setting::set('site_name', $data['site_name'] ?? '');
Setting::set('site_logo', $data['site_logo'] ?? '');
Setting::set('primary_color', $data['primary_color'] ?? '#3b82f6');
Setting::set('secondary_color', $data['secondary_color'] ?? '#8b5cf6');
Setting::set('accent_color', $data['accent_color'] ?? '#10b981');
Setting::set('site_description', $data['site_description'] ?? '');
Setting::set('contact_email', $data['contact_email'] ?? '');
Setting::set('maintenance_mode', $data['maintenance_mode'] ?? false, 'boolean');
Setting::set('enable_registration', $data['enable_registration'] ?? false, 'boolean');
Notification::make()
->title('Settings saved successfully')
->success()
->send();
}
}

View File

@@ -0,0 +1,231 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\AuditResource\Pages;
use App\Models\Audit;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Infolists;
use Filament\Infolists\Infolist;
use Illuminate\Database\Eloquent\Builder;
class AuditResource extends Resource
{
protected static ?string $model = Audit::class;
protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list';
protected static ?string $navigationGroup = 'System';
protected static ?string $navigationLabel = 'Audit Trail';
protected static ?int $navigationSort = 100;
protected static ?string $modelLabel = 'Audit Log';
protected static ?string $pluralModelLabel = 'Audit Trail';
public static function canAccess(): bool
{
return auth()->user()?->can('audit.view') ?? false;
}
public static function canCreate(): bool
{
return false;
}
public static function canEdit($record): bool
{
return false;
}
public static function canDelete($record): bool
{
return false;
}
public static function form(Form $form): Form
{
return $form->schema([]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('created_at')
->label('Date/Time')
->dateTime('M j, Y H:i:s')
->sortable(),
Tables\Columns\TextColumn::make('user.name')
->label('User')
->default('System')
->searchable()
->sortable(),
Tables\Columns\BadgeColumn::make('event')
->label('Action')
->colors([
'success' => 'created',
'warning' => 'updated',
'danger' => 'deleted',
'info' => 'restored',
])
->formatStateUsing(fn (string $state): string => ucfirst($state)),
Tables\Columns\TextColumn::make('auditable_type')
->label('Model')
->formatStateUsing(fn (string $state): string => class_basename($state))
->sortable(),
Tables\Columns\TextColumn::make('auditable_id')
->label('Record ID')
->sortable(),
Tables\Columns\TextColumn::make('ip_address')
->label('IP Address')
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('url')
->label('URL')
->limit(30)
->toggleable(isToggledHiddenByDefault: true),
])
->defaultSort('created_at', 'desc')
->filters([
Tables\Filters\SelectFilter::make('event')
->label('Action')
->options([
'created' => 'Created',
'updated' => 'Updated',
'deleted' => 'Deleted',
'restored' => 'Restored',
]),
Tables\Filters\SelectFilter::make('user_id')
->label('User')
->relationship('user', 'name')
->searchable()
->preload(),
Tables\Filters\SelectFilter::make('auditable_type')
->label('Model')
->options(fn () => Audit::query()
->distinct()
->pluck('auditable_type')
->mapWithKeys(fn ($type) => [$type => class_basename($type)])
->toArray()
),
Tables\Filters\Filter::make('created_at')
->form([
Forms\Components\DatePicker::make('from')
->label('From Date'),
Forms\Components\DatePicker::make('until')
->label('Until Date'),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['from'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['until'],
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['from'] ?? null) {
$indicators['from'] = 'From: ' . $data['from'];
}
if ($data['until'] ?? null) {
$indicators['until'] = 'Until: ' . $data['until'];
}
return $indicators;
}),
])
->actions([
Tables\Actions\ViewAction::make(),
])
->bulkActions([])
->poll('60s');
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Infolists\Components\Section::make('Audit Details')
->schema([
Infolists\Components\Grid::make(3)
->schema([
Infolists\Components\TextEntry::make('created_at')
->label('Date/Time')
->dateTime('F j, Y H:i:s'),
Infolists\Components\TextEntry::make('user.name')
->label('User')
->default('System'),
Infolists\Components\TextEntry::make('event')
->label('Action')
->badge()
->color(fn (string $state): string => match ($state) {
'created' => 'success',
'updated' => 'warning',
'deleted' => 'danger',
'restored' => 'info',
default => 'gray',
})
->formatStateUsing(fn (string $state): string => ucfirst($state)),
]),
Infolists\Components\Grid::make(3)
->schema([
Infolists\Components\TextEntry::make('auditable_type')
->label('Model')
->formatStateUsing(fn (string $state): string => class_basename($state)),
Infolists\Components\TextEntry::make('auditable_id')
->label('Record ID'),
Infolists\Components\TextEntry::make('ip_address')
->label('IP Address')
->default('N/A'),
]),
Infolists\Components\TextEntry::make('url')
->label('URL')
->columnSpanFull(),
]),
Infolists\Components\Section::make('Changes')
->schema([
Infolists\Components\ViewEntry::make('changes')
->view('filament.infolists.entries.audit-changes')
->columnSpanFull(),
]),
]);
}
public static function getRelations(): array
{
return [];
}
public static function getPages(): array
{
return [
'index' => Pages\ListAudits::route('/'),
'view' => Pages\ViewAudit::route('/{record}'),
];
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Filament\Resources\AuditResource\Pages;
use App\Filament\Resources\AuditResource;
use Filament\Resources\Pages\ListRecords;
class ListAudits extends ListRecords
{
protected static string $resource = AuditResource::class;
protected function getHeaderActions(): array
{
return [];
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Filament\Resources\AuditResource\Pages;
use App\Filament\Resources\AuditResource;
use Filament\Resources\Pages\ViewRecord;
class ViewAudit extends ViewRecord
{
protected static string $resource = AuditResource::class;
protected function getHeaderActions(): array
{
return [];
}
}

View File

@@ -0,0 +1,146 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\MenuResource\Pages;
use App\Filament\Resources\MenuResource\RelationManagers;
use App\Models\Menu;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Str;
class MenuResource extends Resource
{
protected static ?string $model = Menu::class;
protected static ?string $navigationIcon = 'heroicon-o-bars-3';
protected static ?string $navigationGroup = 'Settings';
protected static ?int $navigationSort = 10;
public static function canAccess(): bool
{
$user = auth()->user();
return $user?->hasRole('admin') || $user?->can('menus.view');
}
public static function canCreate(): bool
{
$user = auth()->user();
return $user?->hasRole('admin') || $user?->can('menus.create');
}
public static function canEdit($record): bool
{
$user = auth()->user();
return $user?->hasRole('admin') || $user?->can('menus.edit');
}
public static function canDelete($record): bool
{
$user = auth()->user();
return $user?->hasRole('admin') || $user?->can('menus.delete');
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('Menu Details')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255)
->live(onBlur: true)
->afterStateUpdated(fn ($state, Forms\Set $set) =>
$set('slug', Str::slug($state))
),
Forms\Components\TextInput::make('slug')
->required()
->maxLength(255)
->unique(ignoreRecord: true),
Forms\Components\Select::make('location')
->options([
'header' => 'Header Navigation',
'footer' => 'Footer Navigation',
'sidebar' => 'Sidebar Navigation',
])
->placeholder('Select a location'),
Forms\Components\Toggle::make('is_active')
->label('Active')
->default(true),
])->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('slug')
->searchable()
->badge()
->color('gray'),
Tables\Columns\TextColumn::make('location')
->badge()
->color(fn (?string $state) => match ($state) {
'header' => 'success',
'footer' => 'warning',
'sidebar' => 'info',
default => 'gray',
}),
Tables\Columns\TextColumn::make('allItems_count')
->label('Items')
->counts('allItems')
->badge(),
Tables\Columns\IconColumn::make('is_active')
->label('Active')
->boolean(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\SelectFilter::make('location')
->options([
'header' => 'Header',
'footer' => 'Footer',
'sidebar' => 'Sidebar',
]),
Tables\Filters\TernaryFilter::make('is_active')
->label('Active'),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
RelationManagers\ItemsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListMenus::route('/'),
'create' => Pages\CreateMenu::route('/create'),
'edit' => Pages\EditMenu::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\MenuResource\Pages;
use App\Filament\Resources\MenuResource;
use Filament\Resources\Pages\CreateRecord;
class CreateMenu extends CreateRecord
{
protected static string $resource = MenuResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\MenuResource\Pages;
use App\Filament\Resources\MenuResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditMenu extends EditRecord
{
protected static string $resource = MenuResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\MenuResource\Pages;
use App\Filament\Resources\MenuResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListMenus extends ListRecords
{
protected static string $resource = MenuResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,153 @@
<?php
namespace App\Filament\Resources\MenuResource\RelationManagers;
use App\Models\MenuItem;
use App\Services\MenuService;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Spatie\Permission\Models\Permission;
class ItemsRelationManager extends RelationManager
{
protected static string $relationship = 'allItems';
protected static ?string $title = 'Menu Items';
public function form(Form $form): Form
{
$menuService = app(MenuService::class);
return $form
->schema([
Forms\Components\Section::make('Item Details')
->schema([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
Forms\Components\Select::make('type')
->options([
'link' => 'External Link',
'route' => 'Named Route',
'module' => 'Module',
])
->default('link')
->required()
->live(),
Forms\Components\TextInput::make('url')
->label('URL')
->url()
->visible(fn (Forms\Get $get) => $get('type') === 'link')
->required(fn (Forms\Get $get) => $get('type') === 'link'),
Forms\Components\Select::make('route')
->label('Route Name')
->options(fn () => $menuService->getAvailableRoutes())
->searchable()
->visible(fn (Forms\Get $get) => $get('type') === 'route')
->required(fn (Forms\Get $get) => $get('type') === 'route'),
Forms\Components\Select::make('module')
->label('Module')
->options(fn () => $menuService->getAvailableModules())
->searchable()
->visible(fn (Forms\Get $get) => $get('type') === 'module')
->required(fn (Forms\Get $get) => $get('type') === 'module')
->helperText('Users need view permission for this module to see this item'),
])->columns(2),
Forms\Components\Section::make('Permissions & Display')
->schema([
Forms\Components\Select::make('parent_id')
->label('Parent Item')
->options(fn () => MenuItem::where('menu_id', $this->ownerRecord->id)
->whereNull('parent_id')
->pluck('title', 'id'))
->placeholder('None (Top Level)')
->searchable(),
Forms\Components\Select::make('permission')
->label('Required Permission')
->options(fn () => Permission::pluck('name', 'name'))
->searchable()
->placeholder('No specific permission required')
->helperText('If set, user must have this permission to see this item'),
Forms\Components\TextInput::make('icon')
->placeholder('heroicon-o-home')
->helperText('Heroicon name or custom icon class'),
Forms\Components\Select::make('target')
->options([
'_self' => 'Same Window',
'_blank' => 'New Tab',
])
->default('_self'),
Forms\Components\TextInput::make('order')
->numeric()
->default(0)
->helperText('Lower numbers appear first'),
Forms\Components\Toggle::make('is_active')
->label('Active')
->default(true),
])->columns(2),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('title')
->reorderable('order')
->defaultSort('order')
->columns([
Tables\Columns\TextColumn::make('title')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('parent.title')
->label('Parent')
->placeholder('—')
->badge()
->color('gray'),
Tables\Columns\TextColumn::make('type')
->badge()
->color(fn (string $state) => match ($state) {
'link' => 'info',
'route' => 'success',
'module' => 'warning',
default => 'gray',
}),
Tables\Columns\TextColumn::make('module')
->placeholder('—')
->toggleable(),
Tables\Columns\TextColumn::make('permission')
->placeholder('—')
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('order')
->sortable(),
Tables\Columns\IconColumn::make('is_active')
->label('Active')
->boolean(),
])
->filters([
Tables\Filters\SelectFilter::make('type')
->options([
'link' => 'External Link',
'route' => 'Named Route',
'module' => 'Module',
]),
Tables\Filters\TernaryFilter::make('is_active')
->label('Active'),
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PermissionResource\Pages;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Spatie\Permission\Models\Permission;
class PermissionResource extends Resource
{
protected static ?string $model = Permission::class;
protected static ?string $navigationIcon = 'heroicon-o-key';
protected static ?string $navigationGroup = 'User Management';
protected static ?int $navigationSort = 3;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('Permission Details')
->schema([
Forms\Components\TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->maxLength(255)
->helperText('Use format: resource.action (e.g., users.create, posts.edit)'),
Forms\Components\Select::make('guard_name')
->options([
'web' => 'Web',
'api' => 'API',
])
->default('web')
->required(),
])->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->badge()
->color('info')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('guard_name')
->badge()
->color('gray'),
Tables\Columns\TextColumn::make('roles_count')
->counts('roles')
->label('Roles')
->badge()
->color('success'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPermissions::route('/'),
'create' => Pages\CreatePermission::route('/create'),
'edit' => Pages\EditPermission::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\PermissionResource\Pages;
use App\Filament\Resources\PermissionResource;
use Filament\Resources\Pages\CreateRecord;
class CreatePermission extends CreateRecord
{
protected static string $resource = PermissionResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PermissionResource\Pages;
use App\Filament\Resources\PermissionResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditPermission extends EditRecord
{
protected static string $resource = PermissionResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PermissionResource\Pages;
use App\Filament\Resources\PermissionResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListPermissions extends ListRecords
{
protected static string $resource = PermissionResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\RoleResource\Pages;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Spatie\Permission\Models\Role;
class RoleResource extends Resource
{
protected static ?string $model = Role::class;
protected static ?string $navigationIcon = 'heroicon-o-shield-check';
protected static ?string $navigationGroup = 'User Management';
protected static ?int $navigationSort = 2;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('Role Details')
->schema([
Forms\Components\TextInput::make('name')
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\Select::make('guard_name')
->options([
'web' => 'Web',
'api' => 'API',
])
->default('web')
->required(),
])->columns(2),
Forms\Components\Section::make('Permissions')
->schema([
Forms\Components\CheckboxList::make('permissions')
->relationship('permissions', 'name')
->columns(3)
->helperText('Select permissions for this role'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->badge()
->color(fn (string $state): string => match ($state) {
'admin' => 'danger',
'editor' => 'warning',
default => 'success',
})
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('guard_name')
->badge()
->color('gray'),
Tables\Columns\TextColumn::make('permissions_count')
->counts('permissions')
->label('Permissions')
->badge()
->color('info'),
Tables\Columns\TextColumn::make('users_count')
->counts('users')
->label('Users')
->badge()
->color('success'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make()
->before(function (Role $record) {
if ($record->name === 'admin') {
throw new \Exception('Cannot delete the admin role.');
}
}),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListRoles::route('/'),
'create' => Pages\CreateRole::route('/create'),
'edit' => Pages\EditRole::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\RoleResource\Pages;
use App\Filament\Resources\RoleResource;
use Filament\Resources\Pages\CreateRecord;
class CreateRole extends CreateRecord
{
protected static string $resource = RoleResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\RoleResource\Pages;
use App\Filament\Resources\RoleResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditRole extends EditRecord
{
protected static string $resource = RoleResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\RoleResource\Pages;
use App\Filament\Resources\RoleResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListRoles extends ListRecords
{
protected static string $resource = RoleResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\UserResource\Pages;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static ?string $navigationIcon = 'heroicon-o-users';
protected static ?string $navigationGroup = 'User Management';
protected static ?int $navigationSort = 1;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make('User Information')
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\DateTimePicker::make('email_verified_at')
->label('Email Verified At'),
])->columns(2),
Forms\Components\Section::make('Password')
->schema([
Forms\Components\TextInput::make('password')
->password()
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create')
->maxLength(255)
->confirmed(),
Forms\Components\TextInput::make('password_confirmation')
->password()
->maxLength(255)
->dehydrated(false),
])->columns(2),
Forms\Components\Section::make('Roles')
->schema([
Forms\Components\CheckboxList::make('roles')
->relationship('roles', 'name')
->columns(3)
->helperText('Assign roles to this user'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('email')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('roles.name')
->badge()
->color('success')
->separator(','),
Tables\Columns\IconColumn::make('email_verified_at')
->label('Verified')
->boolean()
->trueIcon('heroicon-o-check-circle')
->falseIcon('heroicon-o-x-circle'),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\SelectFilter::make('roles')
->relationship('roles', 'name')
->multiple()
->preload(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateUser extends CreateRecord
{
protected static string $resource = UserResource::class;
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditUser extends EditRecord
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListUsers extends ListRecords
{
protected static string $resource = UserResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Helpers;
class ViteHelper
{
/**
* Check if the Vite manifest exists (assets have been built).
*/
public static function manifestExists(): bool
{
return file_exists(public_path('build/manifest.json'));
}
/**
* Get fallback CSS for when Vite assets are not built.
* This provides basic styling so the app remains usable.
*/
public static function fallbackStyles(): string
{
return <<<'CSS'
<style>
/* Fallback styles when Vite assets are not built */
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: ui-sans-serif, system-ui, sans-serif;
margin: 0;
background: #f3f4f6;
color: #111827;
}
.dark body { background: #111827; color: #f9fafb; }
.min-h-screen { min-height: 100vh; }
.bg-gray-100 { background: #f3f4f6; }
.bg-white { background: #fff; }
.shadow { box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.max-w-7xl { max-width: 80rem; margin: 0 auto; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-6 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.font-semibold { font-weight: 600; }
.text-xl { font-size: 1.25rem; }
.text-gray-800 { color: #1f2937; }
a { color: #3b82f6; text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.space-x-4 > * + * { margin-left: 1rem; }
nav { background: #fff; border-bottom: 1px solid #e5e7eb; padding: 1rem; }
.container { max-width: 80rem; margin: 0 auto; padding: 0 1rem; }
button, .btn {
padding: 0.5rem 1rem;
background: #3b82f6;
color: white;
border: none;
border-radius: 0.375rem;
cursor: pointer;
}
button:hover, .btn:hover { background: #2563eb; }
input, select, textarea {
border: 1px solid #d1d5db;
border-radius: 0.375rem;
padding: 0.5rem 0.75rem;
width: 100%;
}
.alert { padding: 1rem; border-radius: 0.375rem; margin-bottom: 1rem; }
.alert-warning { background: #fef3c7; border: 1px solid #f59e0b; color: #92400e; }
</style>
CSS;
}
/**
* Get a warning banner HTML for development.
*/
public static function devWarningBanner(): string
{
if (app()->environment('production')) {
return '';
}
return <<<'HTML'
<div class="alert alert-warning" style="margin:1rem;padding:1rem;background:#fef3c7;border:1px solid #f59e0b;border-radius:0.5rem;color:#92400e;">
<strong>⚠️ Development Notice:</strong> Vite assets are not built.
Run <code style="background:#fde68a;padding:0.125rem 0.25rem;border-radius:0.25rem;">docker-compose run --rm node npm run build</code> to build assets.
</div>
HTML;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*/
public function create(): View
{
return view('auth.login');
}
/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(route('dashboard', absolute: false));
}
/**
* Destroy an authenticated session.
*/
public function destroy(Request $request): RedirectResponse
{
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
class ConfirmablePasswordController extends Controller
{
/**
* Show the confirm password view.
*/
public function show(): View
{
return view('auth.confirm-password');
}
/**
* Confirm the user's password.
*/
public function store(Request $request): RedirectResponse
{
if (! Auth::guard('web')->validate([
'email' => $request->user()->email,
'password' => $request->password,
])) {
throw ValidationException::withMessages([
'password' => __('auth.password'),
]);
}
$request->session()->put('auth.password_confirmed_at', time());
return redirect()->intended(route('dashboard', absolute: false));
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*/
public function store(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false));
}
$request->user()->sendEmailVerificationNotification();
return back()->with('status', 'verification-link-sent');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class EmailVerificationPromptController extends Controller
{
/**
* Display the email verification prompt.
*/
public function __invoke(Request $request): RedirectResponse|View
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(route('dashboard', absolute: false))
: view('auth.verify-email');
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
class NewPasswordController extends Controller
{
/**
* Display the password reset view.
*/
public function create(Request $request): View
{
return view('auth.reset-password', ['request' => $request]);
}
/**
* Handle an incoming new password request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'token' => ['required'],
'email' => ['required', 'email'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function (User $user) use ($request) {
$user->forceFill([
'password' => Hash::make($request->password),
'remember_token' => Str::random(60),
])->save();
event(new PasswordReset($user));
}
);
// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
return $status == Password::PASSWORD_RESET
? redirect()->route('login')->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
class PasswordController extends Controller
{
/**
* Update the user's password.
*/
public function update(Request $request): RedirectResponse
{
$validated = $request->validateWithBag('updatePassword', [
'current_password' => ['required', 'current_password'],
'password' => ['required', Password::defaults(), 'confirmed'],
]);
$request->user()->update([
'password' => Hash::make($validated['password']),
]);
return back()->with('status', 'password-updated');
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\View\View;
class PasswordResetLinkController extends Controller
{
/**
* Display the password reset link request view.
*/
public function create(): View
{
return view('auth.forgot-password');
}
/**
* Handle an incoming password reset link request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'email' => ['required', 'email'],
]);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = Password::sendResetLink(
$request->only('email')
);
return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*/
public function create(): View
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
event(new Registered($user));
Auth::login($user);
return redirect(route('dashboard', absolute: false));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
class ProfileController extends Controller
{
/**
* Display the user's profile form.
*/
public function edit(Request $request): View
{
return view('profile.edit', [
'user' => $request->user(),
]);
}
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$request->user()->save();
return Redirect::route('profile.edit')->with('status', 'profile-updated');
}
/**
* Delete the user's account.
*/
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);
$user = $request->user();
Auth::logout();
$user->delete();
$request->session()->invalidate();
$request->session()->regenerateToken();
return Redirect::to('/');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use App\Models\Setting;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CheckRegistrationEnabled
{
/**
* Handle an incoming request.
* Block registration routes if registration is disabled in settings.
*/
public function handle(Request $request, Closure $next): Response
{
$registrationEnabled = Setting::get('enable_registration', false);
if (!$registrationEnabled) {
abort(403, 'User registration is currently disabled. Please contact an administrator.');
}
return $next($request);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string'],
];
}
/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function authenticate(): void
{
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
/**
* Ensure the login request is not rate limited.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function ensureIsNotRateLimited(): void
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}
event(new Lockout($this));
$seconds = RateLimiter::availableIn($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}
/**
* Get the rate limiting throttle key for the request.
*/
public function throttleKey(): string
{
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProfileUpdateRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'lowercase',
'email',
'max:255',
Rule::unique(User::class)->ignore($this->user()->id),
],
];
}
}

111
src/app/Models/Audit.php Normal file
View File

@@ -0,0 +1,111 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class Audit extends Model
{
protected $table = 'audits';
protected $guarded = [];
protected $casts = [
'old_values' => 'array',
'new_values' => 'array',
];
/**
* Get the user that performed the action.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Get the auditable model.
*/
public function auditable(): MorphTo
{
return $this->morphTo();
}
/**
* Get the event badge color.
*/
public function getEventColorAttribute(): string
{
return match ($this->event) {
'created' => 'success',
'updated' => 'warning',
'deleted' => 'danger',
'restored' => 'info',
default => 'gray',
};
}
/**
* Get a human-readable model name.
*/
public function getModelNameAttribute(): string
{
$class = class_basename($this->auditable_type);
return preg_replace('/(?<!^)[A-Z]/', ' $0', $class);
}
/**
* Get formatted changes for display.
*/
public function getFormattedChangesAttribute(): array
{
$changes = [];
$oldValues = $this->old_values ?? [];
$newValues = $this->new_values ?? [];
$allKeys = array_unique(array_merge(array_keys($oldValues), array_keys($newValues)));
foreach ($allKeys as $key) {
$old = $oldValues[$key] ?? null;
$new = $newValues[$key] ?? null;
if ($old !== $new) {
$changes[] = [
'field' => $key,
'old' => $this->formatValue($old),
'new' => $this->formatValue($new),
];
}
}
return $changes;
}
/**
* Format a value for display.
*/
protected function formatValue($value): string
{
if (is_null($value)) {
return '(empty)';
}
if (is_bool($value)) {
return $value ? 'Yes' : 'No';
}
if (is_array($value)) {
return json_encode($value);
}
$stringValue = (string) $value;
if (strlen($stringValue) > 100) {
return substr($stringValue, 0, 100) . '...';
}
return $stringValue;
}
}

40
src/app/Models/Menu.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Menu extends Model
{
protected $fillable = [
'name',
'slug',
'location',
'is_active',
];
protected $casts = [
'is_active' => 'boolean',
];
public function items(): HasMany
{
return $this->hasMany(MenuItem::class)->whereNull('parent_id')->orderBy('order');
}
public function allItems(): HasMany
{
return $this->hasMany(MenuItem::class)->orderBy('order');
}
public static function findBySlug(string $slug): ?self
{
return static::where('slug', $slug)->where('is_active', true)->first();
}
public static function findByLocation(string $location): ?self
{
return static::where('location', $location)->where('is_active', true)->first();
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Auth;
class MenuItem extends Model
{
protected $fillable = [
'menu_id',
'parent_id',
'title',
'type',
'url',
'route',
'route_params',
'module',
'permission',
'icon',
'target',
'order',
'is_active',
];
protected $casts = [
'route_params' => 'array',
'is_active' => 'boolean',
'order' => 'integer',
];
public function menu(): BelongsTo
{
return $this->belongsTo(Menu::class);
}
public function parent(): BelongsTo
{
return $this->belongsTo(MenuItem::class, 'parent_id');
}
public function children(): HasMany
{
return $this->hasMany(MenuItem::class, 'parent_id')->orderBy('order');
}
public function getUrlAttribute(): ?string
{
return match ($this->type) {
'link' => $this->attributes['url'],
'route' => $this->route ? route($this->route, $this->route_params ?? []) : null,
'module' => $this->module ? route("{$this->module}.index") : null,
default => null,
};
}
public function isVisibleToUser(?User $user = null): bool
{
if (!$this->is_active) {
return false;
}
$user = $user ?? Auth::user();
if (!$user) {
return !$this->permission && !$this->module;
}
if ($user->hasRole('admin')) {
return true;
}
if ($this->permission) {
return $user->can($this->permission);
}
if ($this->module) {
return $user->can("{$this->module}.view");
}
return true;
}
public function getVisibleChildren(?User $user = null): \Illuminate\Support\Collection
{
return $this->children->filter(fn (MenuItem $item) => $item->isVisibleToUser($user));
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
protected $fillable = ['key', 'value', 'type'];
public static function get(string $key, $default = null)
{
$setting = static::where('key', $key)->first();
if (!$setting) {
return $default;
}
return match ($setting->type) {
'boolean' => filter_var($setting->value, FILTER_VALIDATE_BOOLEAN),
'integer' => (int) $setting->value,
'array', 'json' => json_decode($setting->value, true),
default => $setting->value,
};
}
public static function set(string $key, $value, string $type = 'string'): void
{
if (in_array($type, ['array', 'json'])) {
$value = json_encode($value);
}
static::updateOrCreate(
['key' => $key],
['value' => $value, 'type' => $type]
);
}
}

57
src/app/Models/User.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasRoles, HasApiTokens;
public function canAccessPanel(Panel $panel): bool
{
return $this->hasRole('admin');
}
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}

131
src/app/Modules/README.md Normal file
View File

@@ -0,0 +1,131 @@
# Module System
> **🤖 AI Agents**: For EXACT file templates, see [CLAUDE.md](../../../CLAUDE.md)
This Laravel application uses a modular architecture to organize features into self-contained modules.
## Creating a New Module
```bash
# Basic module (no model)
php artisan make:module ProductCatalog
# With a model + Filament resource
php artisan make:module ProductCatalog --model=Product
# With API routes
php artisan make:module ProductCatalog --model=Product --api
# Without Filament admin
php artisan make:module ProductCatalog --model=Product --no-filament
```
## What Gets Created
### Basic module (`make:module Name`):
```
app/Modules/Name/
├── Config/name.php # Module config
├── Database/Migrations/ # Module migrations
├── Database/Seeders/
├── Filament/Resources/ # Admin resources
├── Http/Controllers/NameController.php
├── Http/Middleware/
├── Http/Requests/
├── Models/
├── Policies/
├── Services/
├── Routes/web.php # Frontend routes
├── Resources/views/index.blade.php
├── Permissions.php # Module permissions
└── NameServiceProvider.php # Auto-registered
```
### With `--model=Product`:
Adds:
- `Models/Product.php` (with auditing)
- `Database/Migrations/create_products_table.php`
- `Filament/Resources/ProductResource.php` (full CRUD)
### With `--api`:
Adds:
- `Routes/api.php` (Sanctum-protected)
## Module Features
**ServiceProvider** - Auto-registered, loads routes/views/migrations
**Config** - Module-specific settings with audit configuration
**Permissions** - Pre-defined CRUD permissions
**Filament Admin** - Full CRUD resource with navigation group
**Auditing** - Track all changes via ModuleAuditable trait
**Tests** - Feature tests with permission checks
## Example Usage
```bash
# Create a Stock Management module with Product model
php artisan make:module StockManagement --model=Product --api
# Run migrations
php artisan migrate
# Seed permissions
php artisan db:seed --class=RolePermissionSeeder
# Clear caches
php artisan optimize:clear
```
**Access:**
- Frontend: `http://localhost:8080/stock-management`
- Admin: `http://localhost:8080/admin` → Stock Management section
- API: `http://localhost:8080/api/stock-management`
## Permissions
Each module creates these permissions in `Permissions.php`:
```php
return [
'stock_management.view' => 'View Stock Management',
'stock_management.create' => 'Create Stock Management records',
'stock_management.edit' => 'Edit Stock Management records',
'stock_management.delete' => 'Delete Stock Management records',
];
```
**Permissions are auto-loaded!** When you run `php artisan db:seed --class=RolePermissionSeeder`,
it scans all `app/Modules/*/Permissions.php` files and registers them automatically.
Use in Blade:
```blade
@can('stock_management.view')
<a href="{{ route('stock-management.index') }}">Stock</a>
@endcan
```
Use in Controller:
```php
$this->authorize('stock_management.view');
```
## Audit Configuration
Edit `Config/module_name.php`:
```php
'audit' => [
'enabled' => true,
'strategy' => 'all', // 'all', 'include', 'exclude', 'none'
'include' => [], // Fields to audit (if strategy='include')
'exclude' => ['password'], // Fields to exclude
],
```
## Best Practices
1. **Keep modules independent** - Avoid tight coupling between modules
2. **Use Services** - Put business logic in `Services/`, not controllers
3. **Define clear permissions** - One permission per action
4. **Test your modules** - Run `php artisan test` after creating
5. **Use Filament** - Leverage admin panel for quick CRUD

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Providers;
use App\Models\Setting;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
View::composer('*', function ($view) {
try {
$view->with('siteSettings', [
'name' => Setting::get('site_name', config('app.name', 'Laravel')),
'logo' => Setting::get('site_logo'),
'primary_color' => Setting::get('primary_color', '#3b82f6'),
'secondary_color' => Setting::get('secondary_color', '#8b5cf6'),
'accent_color' => Setting::get('accent_color', '#10b981'),
'description' => Setting::get('site_description'),
'enable_registration' => Setting::get('enable_registration', false),
]);
} catch (\Exception $e) {
$view->with('siteSettings', [
'name' => config('app.name', 'Laravel'),
'logo' => null,
'primary_color' => '#3b82f6',
'secondary_color' => '#8b5cf6',
'accent_color' => '#10b981',
'description' => null,
'enable_registration' => false,
]);
}
});
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Providers\Filament;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\AuthenticateSession;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}

View File

@@ -1,121 +0,0 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
class ModuleServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->registerModules();
}
/**
* Bootstrap services.
*/
public function boot(): void
{
$this->bootModules();
}
/**
* Register all modules.
*/
protected function registerModules(): void
{
$modulesPath = app_path('Modules');
if (!File::isDirectory($modulesPath)) {
return;
}
$modules = File::directories($modulesPath);
foreach ($modules as $modulePath) {
$moduleName = basename($modulePath);
$providerClass = "App\\Modules\\{$moduleName}\\{$moduleName}ServiceProvider";
if (class_exists($providerClass)) {
$this->app->register($providerClass);
}
}
}
/**
* Boot all modules.
*/
protected function bootModules(): void
{
$modulesPath = app_path('Modules');
if (!File::isDirectory($modulesPath)) {
return;
}
$modules = File::directories($modulesPath);
foreach ($modules as $modulePath) {
$moduleName = basename($modulePath);
// Load module config
$configPath = "{$modulePath}/Config";
if (File::isDirectory($configPath)) {
foreach (File::files($configPath) as $file) {
$this->mergeConfigFrom(
$file->getPathname(),
strtolower($moduleName) . '.' . $file->getFilenameWithoutExtension()
);
}
}
// Load module routes
$this->loadModuleRoutes($modulePath, $moduleName);
// Load module views
$viewsPath = "{$modulePath}/Resources/views";
if (File::isDirectory($viewsPath)) {
$this->loadViewsFrom($viewsPath, strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $moduleName)));
}
// Load module migrations
$migrationsPath = "{$modulePath}/Database/Migrations";
if (File::isDirectory($migrationsPath)) {
$this->loadMigrationsFrom($migrationsPath);
}
// Load module translations
$langPath = "{$modulePath}/Resources/lang";
if (File::isDirectory($langPath)) {
$this->loadTranslationsFrom($langPath, strtolower($moduleName));
}
}
}
/**
* Load module routes.
*/
protected function loadModuleRoutes(string $modulePath, string $moduleName): void
{
$routesPath = "{$modulePath}/Routes";
if (!File::isDirectory($routesPath)) {
return;
}
$webRoutes = "{$routesPath}/web.php";
$apiRoutes = "{$routesPath}/api.php";
if (File::exists($webRoutes)) {
$this->loadRoutesFrom($webRoutes);
}
if (File::exists($apiRoutes)) {
$this->loadRoutesFrom($apiRoutes);
}
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace App\Services;
use App\Models\Menu;
use App\Models\MenuItem;
use App\Models\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
class MenuService
{
public function getMenu(string $slugOrLocation, ?User $user = null): ?array
{
$menu = Menu::findBySlug($slugOrLocation) ?? Menu::findByLocation($slugOrLocation);
if (!$menu) {
return null;
}
return $this->buildMenuTree($menu, $user);
}
public function buildMenuTree(Menu $menu, ?User $user = null): array
{
$user = $user ?? Auth::user();
$items = $menu->items()
->with(['children' => fn ($q) => $q->orderBy('order')])
->where('is_active', true)
->get();
return $this->filterAndMapItems($items, $user);
}
protected function filterAndMapItems(Collection $items, ?User $user): array
{
return $items
->filter(fn (MenuItem $item) => $item->isVisibleToUser($user))
->map(fn (MenuItem $item) => $this->mapItem($item, $user))
->values()
->toArray();
}
protected function mapItem(MenuItem $item, ?User $user): array
{
$children = $item->children->count() > 0
? $this->filterAndMapItems($item->children, $user)
: [];
return [
'id' => $item->id,
'title' => $item->title,
'url' => $item->url,
'icon' => $item->icon,
'target' => $item->target,
'is_active' => $this->isActiveUrl($item->url),
'children' => $children,
'has_children' => count($children) > 0,
];
}
protected function isActiveUrl(?string $url): bool
{
if (!$url) {
return false;
}
$currentUrl = request()->url();
$currentPath = request()->path();
if ($url === $currentUrl) {
return true;
}
$urlPath = parse_url($url, PHP_URL_PATH) ?? '';
return $urlPath && str_starts_with('/' . ltrim($currentPath, '/'), $urlPath);
}
public function getAvailableModules(): array
{
$modules = [];
$modulesPath = app_path('Modules');
if (!is_dir($modulesPath)) {
return $modules;
}
foreach (scandir($modulesPath) as $module) {
if ($module === '.' || $module === '..' || !is_dir($modulesPath . '/' . $module)) {
continue;
}
$slug = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $module));
$modules[$slug] = $module;
}
return $modules;
}
public function getAvailableRoutes(): array
{
$routes = [];
foreach (app('router')->getRoutes() as $route) {
$name = $route->getName();
if ($name && !str_starts_with($name, 'filament.') && !str_starts_with($name, 'livewire.')) {
$routes[$name] = $name;
}
}
ksort($routes);
return $routes;
}
}

View File

@@ -0,0 +1,248 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
class ModuleDiscoveryService
{
public function discoverModules(): array
{
$modulesPath = app_path('Modules');
if (!File::exists($modulesPath)) {
return [];
}
$modules = [];
$directories = File::directories($modulesPath);
foreach ($directories as $directory) {
$moduleName = basename($directory);
// Skip non-module directories (like README files)
if (!File::exists("{$directory}/{$moduleName}ServiceProvider.php")) {
continue;
}
$modules[] = $this->getModuleInfo($moduleName, $directory);
}
return $modules;
}
protected function getModuleInfo(string $name, string $path): array
{
$kebabName = Str::kebab($name);
$snakeName = Str::snake($name);
return [
'name' => $name,
'slug' => $kebabName,
'path' => $path,
'config' => $this->getConfig($path, $snakeName),
'models' => $this->getModels($path),
'views' => $this->getViews($path),
'routes' => $this->getRoutes($path, $kebabName),
'migrations' => $this->getMigrations($path),
'filament_resources' => $this->getFilamentResources($path),
'permissions' => $this->getPermissions($path),
'has_api' => File::exists("{$path}/Routes/api.php"),
];
}
protected function getConfig(string $path, string $snakeName): array
{
$configPath = "{$path}/Config/{$snakeName}.php";
if (File::exists($configPath)) {
return require $configPath;
}
return [];
}
protected function getModels(string $path): array
{
$modelsPath = "{$path}/Models";
if (!File::exists($modelsPath)) {
return [];
}
$models = [];
$files = File::files($modelsPath);
foreach ($files as $file) {
if ($file->getExtension() === 'php' && $file->getFilename() !== '.gitkeep') {
$modelName = $file->getFilenameWithoutExtension();
$models[] = [
'name' => $modelName,
'file' => $file->getFilename(),
'path' => $file->getPathname(),
];
}
}
return $models;
}
protected function getViews(string $path): array
{
$viewsPath = "{$path}/Resources/views";
if (!File::exists($viewsPath)) {
return [];
}
return $this->scanViewsRecursive($viewsPath, '');
}
protected function scanViewsRecursive(string $basePath, string $prefix): array
{
$views = [];
$items = File::files($basePath);
foreach ($items as $file) {
if ($file->getExtension() === 'php' && Str::endsWith($file->getFilename(), '.blade.php')) {
$viewName = Str::replaceLast('.blade.php', '', $file->getFilename());
$fullName = $prefix ? "{$prefix}.{$viewName}" : $viewName;
$views[] = [
'name' => $fullName,
'file' => $file->getFilename(),
'path' => $file->getPathname(),
];
}
}
// Scan subdirectories
$directories = File::directories($basePath);
foreach ($directories as $dir) {
$dirName = basename($dir);
$subPrefix = $prefix ? "{$prefix}.{$dirName}" : $dirName;
$views = array_merge($views, $this->scanViewsRecursive($dir, $subPrefix));
}
return $views;
}
protected function getRoutes(string $path, string $kebabName): array
{
$routes = [];
// Get web routes
$webRoutesPath = "{$path}/Routes/web.php";
if (File::exists($webRoutesPath)) {
$routes['web'] = $this->parseRouteFile($webRoutesPath, $kebabName);
}
// Get API routes
$apiRoutesPath = "{$path}/Routes/api.php";
if (File::exists($apiRoutesPath)) {
$routes['api'] = $this->parseRouteFile($apiRoutesPath, "api/{$kebabName}");
}
return $routes;
}
protected function parseRouteFile(string $path, string $prefix): array
{
$content = File::get($path);
$routes = [];
// Parse Route::get, Route::post, etc.
preg_match_all(
"/Route::(get|post|put|patch|delete|any)\s*\(\s*['\"]([^'\"]*)['\"].*?->name\s*\(\s*['\"]([^'\"]*)['\"]|Route::(get|post|put|patch|delete|any)\s*\(\s*['\"]([^'\"]*)['\"].*?\[.*?::class,\s*['\"](\w+)['\"]\]/",
$content,
$matches,
PREG_SET_ORDER
);
foreach ($matches as $match) {
$method = strtoupper($match[1] ?: $match[4]);
$uri = $match[2] ?: $match[5];
$fullUri = $uri === '/' ? "/{$prefix}" : "/{$prefix}{$uri}";
$routes[] = [
'method' => $method,
'uri' => $fullUri,
'name' => $match[3] ?? null,
];
}
return $routes;
}
protected function getMigrations(string $path): array
{
$migrationsPath = "{$path}/Database/Migrations";
if (!File::exists($migrationsPath)) {
return [];
}
$migrations = [];
$files = File::files($migrationsPath);
foreach ($files as $file) {
if ($file->getExtension() === 'php') {
$migrations[] = [
'name' => $file->getFilename(),
'path' => $file->getPathname(),
];
}
}
return $migrations;
}
protected function getFilamentResources(string $path): array
{
$resourcesPath = "{$path}/Filament/Resources";
if (!File::exists($resourcesPath)) {
return [];
}
$resources = [];
$files = File::files($resourcesPath);
foreach ($files as $file) {
if ($file->getExtension() === 'php' && Str::endsWith($file->getFilename(), 'Resource.php')) {
$resourceName = Str::replaceLast('Resource.php', '', $file->getFilename());
$resources[] = [
'name' => $resourceName,
'file' => $file->getFilename(),
'path' => $file->getPathname(),
];
}
}
return $resources;
}
protected function getPermissions(string $path): array
{
$permissionsPath = "{$path}/Permissions.php";
if (File::exists($permissionsPath)) {
return require $permissionsPath;
}
return [];
}
public function getModuleSummary(): array
{
$modules = $this->discoverModules();
return [
'total' => count($modules),
'with_models' => count(array_filter($modules, fn($m) => !empty($m['models']))),
'with_filament' => count(array_filter($modules, fn($m) => !empty($m['filament_resources']))),
'with_api' => count(array_filter($modules, fn($m) => $m['has_api'])),
];
}
}

View File

@@ -0,0 +1,492 @@
<?php
namespace App\Services;
use CzProject\GitPhp\Git;
use CzProject\GitPhp\GitRepository;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ModuleGeneratorService
{
protected string $studlyName;
protected string $kebabName;
protected string $snakeName;
protected string $modulePath;
protected array $logs = [];
protected ?GitRepository $repo = null;
public function generate(string $name, array $options = []): array
{
$this->studlyName = Str::studly($name);
$this->kebabName = Str::kebab($name);
$this->snakeName = Str::snake($name);
$this->modulePath = app_path("Modules/{$this->studlyName}");
$options = array_merge([
'description' => '',
'create_git_branch' => true,
'include_api' => false,
], $options);
// Check if module already exists
if (File::exists($this->modulePath)) {
return [
'success' => false,
'message' => "Module {$this->studlyName} already exists!",
'logs' => $this->logs,
];
}
// Handle Git branching
$branchName = null;
if ($options['create_git_branch']) {
$gitResult = $this->createGitBranch();
if (!$gitResult['success']) {
return $gitResult;
}
$branchName = $gitResult['branch'];
}
// Generate module skeleton
$this->createDirectoryStructure();
$this->createServiceProvider($options['description']);
$this->createConfig($options['description']);
$this->createPermissions();
$this->createController();
$this->createRoutes($options['include_api']);
$this->createViews();
$this->createReadme($options['description']);
$this->registerServiceProvider();
// Git commit
if ($options['create_git_branch'] && $this->repo) {
$this->commitChanges();
}
return [
'success' => true,
'message' => "Module {$this->studlyName} created successfully!",
'module_name' => $this->studlyName,
'module_path' => $this->modulePath,
'branch' => $branchName,
'logs' => $this->logs,
'next_steps' => $this->getNextSteps($branchName),
];
}
protected function createGitBranch(): array
{
try {
$git = new Git();
$repoPath = base_path();
// Check if we're in a git repository
if (!File::exists($repoPath . '/.git')) {
$this->log('⚠ No Git repository found, skipping branch creation');
return ['success' => true, 'branch' => null];
}
$this->repo = $git->open($repoPath);
// Check for uncommitted changes
if ($this->repo->hasChanges()) {
return [
'success' => false,
'message' => 'Git working directory has uncommitted changes. Please commit or stash them first.',
'logs' => $this->logs,
];
}
$branchName = "module/{$this->kebabName}";
// Create and checkout new branch
$this->repo->createBranch($branchName, true);
$this->log("✓ Created and checked out branch: {$branchName}");
return ['success' => true, 'branch' => $branchName];
} catch (\Exception $e) {
return [
'success' => false,
'message' => 'Git error: ' . $e->getMessage(),
'logs' => $this->logs,
];
}
}
protected function commitChanges(): void
{
try {
$this->repo->addAllChanges();
$this->repo->commit("feat: Add {$this->studlyName} module skeleton");
$this->log("✓ Committed changes to Git");
} catch (\Exception $e) {
$this->log("⚠ Git commit failed: " . $e->getMessage());
}
}
protected function createDirectoryStructure(): void
{
$directories = [
'',
'/Config',
'/Database/Migrations',
'/Database/Seeders',
'/Filament/Resources',
'/Http/Controllers',
'/Http/Middleware',
'/Http/Requests',
'/Models',
'/Policies',
'/Services',
'/Routes',
'/Resources/views',
];
foreach ($directories as $dir) {
File::makeDirectory("{$this->modulePath}{$dir}", 0755, true);
}
// Create .gitkeep files in empty directories
$emptyDirs = [
'/Database/Migrations',
'/Database/Seeders',
'/Filament/Resources',
'/Http/Middleware',
'/Http/Requests',
'/Models',
'/Policies',
'/Services',
];
foreach ($emptyDirs as $dir) {
File::put("{$this->modulePath}{$dir}/.gitkeep", '');
}
$this->log("✓ Created directory structure");
}
protected function createServiceProvider(string $description): void
{
$stub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName};
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
class {$this->studlyName}ServiceProvider extends ServiceProvider
{
public function register(): void
{
\$this->mergeConfigFrom(
__DIR__ . '/Config/{$this->snakeName}.php',
'{$this->snakeName}'
);
}
public function boot(): void
{
\$this->loadMigrationsFrom(__DIR__ . '/Database/Migrations');
\$this->loadViewsFrom(__DIR__ . '/Resources/views', '{$this->kebabName}');
\$this->registerRoutes();
\$this->registerPermissions();
}
protected function registerRoutes(): void
{
Route::middleware(['web', 'auth'])
->prefix('{$this->kebabName}')
->name('{$this->kebabName}.')
->group(__DIR__ . '/Routes/web.php');
if (file_exists(__DIR__ . '/Routes/api.php')) {
Route::middleware(['api', 'auth:sanctum'])
->prefix('api/{$this->kebabName}')
->name('api.{$this->kebabName}.')
->group(__DIR__ . '/Routes/api.php');
}
}
protected function registerPermissions(): void
{
// Permissions are registered via RolePermissionSeeder
// See: Permissions.php in this module
}
}
PHP;
File::put("{$this->modulePath}/{$this->studlyName}ServiceProvider.php", $stub);
$this->log("✓ Created ServiceProvider");
}
protected function createConfig(string $description): void
{
$stub = <<<PHP
<?php
return [
'name' => '{$this->studlyName}',
'slug' => '{$this->kebabName}',
'description' => '{$description}',
'version' => '1.0.0',
'audit' => [
'enabled' => true,
'strategy' => 'all', // 'all', 'include', 'exclude', 'none'
'include' => [],
'exclude' => [],
],
];
PHP;
File::put("{$this->modulePath}/Config/{$this->snakeName}.php", $stub);
$this->log("✓ Created Config");
}
protected function createPermissions(): void
{
$stub = <<<PHP
<?php
return [
'{$this->snakeName}.view' => 'View {$this->studlyName}',
'{$this->snakeName}.create' => 'Create {$this->studlyName} records',
'{$this->snakeName}.edit' => 'Edit {$this->studlyName} records',
'{$this->snakeName}.delete' => 'Delete {$this->studlyName} records',
];
PHP;
File::put("{$this->modulePath}/Permissions.php", $stub);
$this->log("✓ Created Permissions");
}
protected function createController(): void
{
$stub = <<<PHP
<?php
namespace App\Modules\\{$this->studlyName}\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class {$this->studlyName}Controller extends Controller
{
public function index()
{
\$this->authorize('{$this->snakeName}.view');
return view('{$this->kebabName}::index');
}
}
PHP;
File::put("{$this->modulePath}/Http/Controllers/{$this->studlyName}Controller.php", $stub);
$this->log("✓ Created Controller");
}
protected function createRoutes(bool $includeApi): void
{
// Web routes
$webStub = <<<PHP
<?php
use App\Modules\\{$this->studlyName}\Http\Controllers\\{$this->studlyName}Controller;
use Illuminate\Support\Facades\Route;
Route::get('/', [{$this->studlyName}Controller::class, 'index'])->name('index');
// Add more routes here:
// Route::get('/create', [{$this->studlyName}Controller::class, 'create'])->name('create');
// Route::post('/', [{$this->studlyName}Controller::class, 'store'])->name('store');
// Route::get('/{id}', [{$this->studlyName}Controller::class, 'show'])->name('show');
// Route::get('/{id}/edit', [{$this->studlyName}Controller::class, 'edit'])->name('edit');
// Route::put('/{id}', [{$this->studlyName}Controller::class, 'update'])->name('update');
// Route::delete('/{id}', [{$this->studlyName}Controller::class, 'destroy'])->name('destroy');
PHP;
File::put("{$this->modulePath}/Routes/web.php", $webStub);
// API routes (if requested)
if ($includeApi) {
$apiStub = <<<PHP
<?php
use Illuminate\Support\Facades\Route;
Route::middleware('auth:sanctum')->group(function () {
// API routes here
// Route::get('/', fn() => response()->json(['message' => '{$this->studlyName} API']));
});
PHP;
File::put("{$this->modulePath}/Routes/api.php", $apiStub);
$this->log("✓ Created Routes (web + api)");
} else {
$this->log("✓ Created Routes (web)");
}
}
protected function createViews(): void
{
$stub = <<<BLADE
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('{$this->studlyName}') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 text-gray-900 dark:text-gray-100">
<h3 class="text-lg font-medium mb-4">{{ __('{$this->studlyName} Module') }}</h3>
<p class="text-gray-600 dark:text-gray-400">
This is your new module. Start building by adding models, controllers, and views.
</p>
<div class="mt-6 p-4 bg-gray-50 dark:bg-gray-900 rounded-lg">
<h4 class="font-medium mb-2">Quick Start:</h4>
<ul class="list-disc list-inside text-sm space-y-1">
<li>Add models in <code>app/Modules/{$this->studlyName}/Models/</code></li>
<li>Add migrations in <code>app/Modules/{$this->studlyName}/Database/Migrations/</code></li>
<li>Add Filament resources in <code>app/Modules/{$this->studlyName}/Filament/Resources/</code></li>
<li>Extend routes in <code>app/Modules/{$this->studlyName}/Routes/web.php</code></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</x-app-layout>
BLADE;
File::put("{$this->modulePath}/Resources/views/index.blade.php", $stub);
$this->log("✓ Created Views");
}
protected function createReadme(string $description): void
{
$stub = <<<MD
# {$this->studlyName} Module
{$description}
## Structure
```
{$this->studlyName}/
├── Config/{$this->snakeName}.php # Module configuration
├── Database/
├── Migrations/ # Database migrations
└── Seeders/ # Database seeders
├── Filament/Resources/ # Admin panel resources
├── Http/
├── Controllers/ # HTTP controllers
├── Middleware/ # Module middleware
└── Requests/ # Form requests
├── Models/ # Eloquent models
├── Policies/ # Authorization policies
├── Services/ # Business logic services
├── Routes/
├── web.php # Web routes
└── api.php # API routes (if enabled)
├── Resources/views/ # Blade templates
├── Permissions.php # Module permissions
├── {$this->studlyName}ServiceProvider.php
└── README.md
```
## Permissions
| Permission | Description |
|------------|-------------|
| `{$this->snakeName}.view` | View {$this->studlyName} |
| `{$this->snakeName}.create` | Create records |
| `{$this->snakeName}.edit` | Edit records |
| `{$this->snakeName}.delete` | Delete records |
## Routes
| Method | URI | Name | Description |
|--------|-----|------|-------------|
| GET | `/{$this->kebabName}` | `{$this->kebabName}.index` | Module index |
## Getting Started
1. **Add a Model:**
```bash
# Create model manually or use artisan
php artisan make:model Modules/{$this->studlyName}/Models/YourModel -m
```
2. **Run Migrations:**
```bash
php artisan migrate
```
3. **Seed Permissions:**
```bash
php artisan db:seed --class=RolePermissionSeeder
```
4. **Add Filament Resource:**
Create resources in `Filament/Resources/` following the Filament documentation.
## Configuration
Edit `Config/{$this->snakeName}.php` to customize module settings including audit behavior.
MD;
File::put("{$this->modulePath}/README.md", $stub);
$this->log("✓ Created README.md");
}
protected function registerServiceProvider(): void
{
$providersPath = base_path('bootstrap/providers.php');
if (File::exists($providersPath)) {
$content = File::get($providersPath);
$providerClass = "App\\Modules\\{$this->studlyName}\\{$this->studlyName}ServiceProvider::class";
if (!str_contains($content, $providerClass)) {
$content = preg_replace(
'/(\];)/',
" {$providerClass},\n$1",
$content
);
File::put($providersPath, $content);
$this->log("✓ Registered ServiceProvider");
}
} else {
$this->log("⚠ Could not auto-register ServiceProvider");
}
}
protected function getNextSteps(?string $branchName): array
{
$steps = [
"Run migrations: `php artisan migrate`",
"Seed permissions: `php artisan db:seed --class=RolePermissionSeeder`",
"Clear caches: `php artisan optimize:clear`",
"Access frontend: `/{$this->kebabName}`",
];
if ($branchName) {
$steps[] = "Push branch: `git push -u origin {$branchName}`";
$steps[] = "Create merge request when ready";
}
return $steps;
}
protected function log(string $message): void
{
$this->logs[] = $message;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace App\Traits;
use OwenIt\Auditing\Auditable;
trait ModuleAuditable
{
use Auditable;
/**
* Get the audit configuration from module config.
*/
public function getAuditConfig(): array
{
$moduleName = $this->getModuleName();
return config("{$moduleName}.audit", [
'enabled' => true,
'strategy' => 'all',
'include' => [],
'exclude' => [],
]);
}
/**
* Determine if auditing is enabled for this model.
*/
public function isAuditingEnabled(): bool
{
$config = $this->getAuditConfig();
return $config['enabled'] ?? true;
}
/**
* Get fields to include in audit (if strategy is 'include').
*/
public function getAuditInclude(): array
{
$config = $this->getAuditConfig();
if (($config['strategy'] ?? 'all') === 'include') {
return $config['include'] ?? [];
}
return [];
}
/**
* Get fields to exclude from audit.
*/
public function getAuditExclude(): array
{
$config = $this->getAuditConfig();
return array_merge(
$this->auditExclude ?? [],
$config['exclude'] ?? []
);
}
/**
* Determine the module name from the model's namespace.
*/
protected function getModuleName(): string
{
$class = get_class($this);
// Extract module name from namespace: App\Modules\{ModuleName}\Models\...
if (preg_match('/App\\\\Modules\\\\([^\\\\]+)\\\\/', $class, $matches)) {
return \Illuminate\Support\Str::snake($matches[1]);
}
return 'app';
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\View\View;
class AppLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.app');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\View\Components;
use App\Services\MenuService;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class FrontendMenu extends Component
{
public array $items = [];
public function __construct(
public string $menu = 'header',
public string $class = '',
) {
$menuService = app(MenuService::class);
$this->items = $menuService->getMenu($menu) ?? [];
}
public function render(): View
{
return view('components.frontend-menu');
}
public function hasItems(): bool
{
return count($this->items) > 0;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\View\Components;
use App\Services\MenuService;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class FrontendMenuResponsive extends Component
{
public array $items = [];
public function __construct(
public string $menu = 'header',
public string $class = '',
) {
$menuService = app(MenuService::class);
$this->items = $menuService->getMenu($menu) ?? [];
}
public function render(): View
{
return view('components.frontend-menu-responsive');
}
public function hasItems(): bool
{
return count($this->items) > 0;
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\View\View;
class GuestLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.guest');
}
}

15
src/artisan Normal file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Input\ArgvInput;
define('LARAVEL_START', microtime(true));
// Register the Composer autoloader...
require __DIR__.'/vendor/autoload.php';
// Bootstrap Laravel and handle the command...
$status = (require_once __DIR__.'/bootstrap/app.php')
->handleCommand(new ArgvInput);
exit($status);

21
src/bootstrap/app.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->alias([
'registration.enabled' => \App\Http\Middleware\CheckRegistrationEnabled::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();

2
src/bootstrap/cache/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

View File

@@ -0,0 +1,6 @@
<?php
return [
App\Providers\AppServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
];

82
src/composer.json Normal file
View File

@@ -0,0 +1,82 @@
{
"$schema": "https://getcomposer.org/schema.json",
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.2",
"filament/filament": "^3.2",
"laravel/framework": "^11.31",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"owen-it/laravel-auditing": "^14.0",
"spatie/flare-client-php": "^1.10",
"spatie/laravel-ignition": "^2.11",
"spatie/laravel-permission": "^6.24"
},
"require-dev": {
"czproject/git-php": "^4.6",
"fakerphp/faker": "^1.23",
"laravel/breeze": "^2.3",
"laravel/pail": "^1.1",
"laravel/pint": "^1.27",
"laravel/sail": "^1.26",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.1",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.2",
"phpunit/phpunit": "^11.0.1"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"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"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}

11679
src/composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

126
src/config/app.php Normal file
View File

@@ -0,0 +1,126 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application, which will be used when the
| framework needs to place the application's name in a notification or
| other UI elements where an application name needs to be displayed.
|
*/
'name' => env('APP_NAME', 'Laravel'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services the application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
/*
|--------------------------------------------------------------------------
| Application Debug Mode
|--------------------------------------------------------------------------
|
| When your application is in debug mode, detailed error messages with
| stack traces will be shown on every error that occurs within your
| application. If disabled, a simple generic error page is shown.
|
*/
'debug' => (bool) env('APP_DEBUG', false),
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| the application so that it's available within Artisan commands.
|
*/
'url' => env('APP_URL', 'http://localhost'),
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. The timezone
| is set to "UTC" by default as it is suitable for most use cases.
|
*/
'timezone' => env('APP_TIMEZONE', 'UTC'),
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by Laravel's translation / localization methods. This option can be
| set to any locale for which you plan to have translation strings.
|
*/
'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is utilized by Laravel's encryption services and should be set
| to a random, 32 character string to ensure that all encrypted values
| are secure. You should do this prior to deploying the application.
|
*/
'cipher' => 'AES-256-CBC',
'key' => env('APP_KEY'),
'previous_keys' => [
...array_filter(
explode(',', env('APP_PREVIOUS_KEYS', ''))
),
],
/*
|--------------------------------------------------------------------------
| Maintenance Mode Driver
|--------------------------------------------------------------------------
|
| These configuration options determine the driver used to determine and
| manage Laravel's "maintenance mode" status. The "cache" driver will
| allow maintenance mode to be controlled across multiple machines.
|
| Supported drivers: "file", "cache"
|
*/
'maintenance' => [
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
'store' => env('APP_MAINTENANCE_STORE', 'database'),
],
];

115
src/config/auth.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option defines the default authentication "guard" and password
| reset "broker" for your application. You may change these values
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => env('AUTH_GUARD', 'web'),
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| which utilizes session storage plus the Eloquent user provider.
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| Supported: "session"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication guards have a user provider, which defines how the
| users are actually retrieved out of your database or other storage
| system used by the application. Typically, Eloquent is utilized.
|
| If you have multiple user tables or models you may configure multiple
| providers to represent the model / table. These providers may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| These configuration options specify the behavior of Laravel's password
| reset functionality, including the table utilized for token storage
| and the user provider that is invoked to actually retrieve users.
|
| The expiry time is the number of minutes that each reset token will be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
| The throttle setting is the number of seconds a user must wait before
| generating more password reset tokens. This prevents the user from
| quickly generating a very large amount of password reset tokens.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| window expires and users are asked to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),
];

108
src/config/cache.php Normal file
View File

@@ -0,0 +1,108 @@
<?php
use Illuminate\Support\Str;
return [
/*
|--------------------------------------------------------------------------
| Default Cache Store
|--------------------------------------------------------------------------
|
| This option controls the default cache store that will be used by the
| framework. This connection is utilized if another isn't explicitly
| specified when running a cache operation inside the application.
|
*/
'default' => env('CACHE_STORE', 'database'),
/*
|--------------------------------------------------------------------------
| Cache Stores
|--------------------------------------------------------------------------
|
| Here you may define all of the cache "stores" for your application as
| well as their drivers. You may even define multiple stores for the
| same cache driver to group types of items stored in your caches.
|
| Supported drivers: "array", "database", "file", "memcached",
| "redis", "dynamodb", "octane", "null"
|
*/
'stores' => [
'array' => [
'driver' => 'array',
'serialize' => false,
],
'database' => [
'driver' => 'database',
'connection' => env('DB_CACHE_CONNECTION'),
'table' => env('DB_CACHE_TABLE', 'cache'),
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
'lock_path' => storage_path('framework/cache/data'),
],
'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],
'redis' => [
'driver' => 'redis',
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
],
'dynamodb' => [
'driver' => 'dynamodb',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
'endpoint' => env('DYNAMODB_ENDPOINT'),
],
'octane' => [
'driver' => 'octane',
],
],
/*
|--------------------------------------------------------------------------
| Cache Key Prefix
|--------------------------------------------------------------------------
|
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
| stores, there might be other applications using the same cache. For
| that reason, you may prefix every cache key to avoid collisions.
|
*/
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
];

View File

@@ -1,41 +0,0 @@
<?php
/**
* CORS Configuration Example
*
* Copy this to config/cors.php in your Laravel app if you need
* to customize CORS settings beyond the defaults.
*/
return [
/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Settings for handling Cross-Origin Resource Sharing (CORS).
| Adjust these based on your API requirements.
|
*/
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => [
env('FRONTEND_URL', 'http://localhost:3000'),
// Add other allowed origins here
],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => true,
];

Some files were not shown because too many files have changed in this diff Show More