Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ __pycache__/
*.pyo
db.sqlite3

# PHP / Laravel
vendor/
composer.phar
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
storage/logs/*
bootstrap/cache/*
*.sqlite
*.sqlite-journal

# Environment variables
.env
.env.local
Expand Down
18 changes: 18 additions & 0 deletions basics/laravel/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
APP_NAME="PostHog Laravel Example"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost:8000

DB_CONNECTION=sqlite
# DB_DATABASE will use default database/database.sqlite

CACHE_DRIVER=file
CACHE_STORE=file

SESSION_DRIVER=file
SESSION_LIFETIME=120

POSTHOG_API_KEY=your_posthog_api_key_here
POSTHOG_HOST=https://us.i.posthog.com
POSTHOG_DISABLED=false
11 changes: 11 additions & 0 deletions basics/laravel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Keep directory structure with .gitkeep files
!/storage/framework/cache/.gitkeep
!/storage/framework/sessions/.gitkeep
!/storage/framework/views/.gitkeep
!/storage/logs/.gitkeep
!/bootstrap/cache/.gitkeep

# Laravel-specific
/public/hot
/public/storage
.env.backup
214 changes: 214 additions & 0 deletions basics/laravel/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# Laravel PostHog Example - Implementation Summary

This document summarizes the implementation of the Laravel PostHog example application, ported from the Flask version.

## ✅ Completed Implementation

### Core Application Structure

**Models & Database**
- ✅ User model with PostHog properties helper method
- ✅ User migration with `is_staff` field
- ✅ Database seeder for default admin user
- ✅ SQLite database configuration

**PostHog Integration**
- ✅ PostHog configuration file (`config/posthog.php`)
- ✅ PostHogService class with all core methods:
- `identify()` - User identification
- `capture()` - Event tracking
- `captureException()` - Error tracking
- `isFeatureEnabled()` - Feature flag checking
- `getFeatureFlagPayload()` - Feature flag payload retrieval

**Authentication (Livewire Components)**
- ✅ Login component with PostHog tracking
- ✅ Register component with PostHog tracking
- ✅ Logout route with PostHog tracking

**Core Features (Livewire Components)**
- ✅ Dashboard - Feature flag demonstration
- ✅ Burrito Tracker - Custom event tracking
- ✅ Profile - Error tracking demonstration

**API Controllers**
- ✅ BurritoController - API endpoint for burrito tracking
- ✅ ErrorTestController - Manual error capture demonstration

**Views & Layouts**
- ✅ App layout (authenticated users)
- ✅ Guest layout (unauthenticated users)
- ✅ All Livewire view files with inline styling
- ✅ Error pages (404, 500)

**Routes**
- ✅ Web routes (authentication, dashboard, burrito, profile, logout)
- ✅ API routes (burrito tracking, error testing)

**Configuration**
- ✅ Environment example file
- ✅ Composer.json with dependencies
- ✅ Laravel config files (app, auth, database, session)
- ✅ .gitignore

**Documentation**
- ✅ Comprehensive README
- ✅ Implementation plan (php-plan.md)

## 📋 Features Implemented

### 1. User Authentication
- Login with PostHog identification
- Registration with PostHog tracking
- Logout with event capture
- Session management

### 2. PostHog Analytics
- User identification on login/signup
- Person properties (email, is_staff, date_joined)
- Custom event tracking (burrito considerations)
- Dashboard views tracking

### 3. Feature Flags
- Feature flag checking (`new-dashboard-feature`)
- Feature flag payload retrieval
- Conditional UI rendering based on flags

### 4. Error Tracking
- Manual exception capture
- Error ID generation
- Test endpoint with optional capture (`?capture=true/false`)

### 5. UI/UX
- Responsive layouts
- Flash messages for user feedback
- Livewire reactivity for burrito counter
- Loading states on buttons

## 🎯 PostHog Integration Points

| Feature | Location | PostHog Method |
|---------|----------|----------------|
| User Login | `Login.php:23-27` | `identify()` + `capture()` |
| User Signup | `Register.php:29-32` | `identify()` + `capture()` |
| User Logout | `web.php:25` | `capture()` |
| Dashboard View | `Dashboard.php:18` | `capture()` |
| Feature Flag Check | `Dashboard.php:21-25` | `isFeatureEnabled()` |
| Feature Flag Payload | `Dashboard.php:28-31` | `getFeatureFlagPayload()` |
| Burrito Tracking | `BurritoTracker.php:22-24` | `identify()` + `capture()` |
| Profile View | `Profile.php:14` | `capture()` |
| Error Capture | `ErrorTestController.php:22-24` | `identify()` + `captureException()` |

## 📁 File Structure

```
basics/laravel/
├── app/
│ ├── Http/
│ │ ├── Controllers/
│ │ │ ├── Controller.php
│ │ │ └── Api/
│ │ │ ├── BurritoController.php
│ │ │ └── ErrorTestController.php
│ │ └── Livewire/
│ │ ├── Auth/
│ │ │ ├── Login.php
│ │ │ └── Register.php
│ │ ├── Dashboard.php
│ │ ├── BurritoTracker.php
│ │ └── Profile.php
│ ├── Models/
│ │ └── User.php
│ └── Services/
│ └── PostHogService.php
├── config/
│ ├── app.php
│ ├── auth.php
│ ├── database.php
│ ├── posthog.php
│ └── session.php
├── database/
│ ├── migrations/
│ │ └── 2024_01_01_000000_create_users_table.php
│ └── seeders/
│ └── DatabaseSeeder.php
├── resources/
│ └── views/
│ ├── components/
│ │ └── layouts/
│ │ ├── app.blade.php
│ │ └── guest.blade.php
│ ├── livewire/
│ │ ├── auth/
│ │ │ ├── login.blade.php
│ │ │ └── register.blade.php
│ │ ├── dashboard.blade.php
│ │ ├── burrito-tracker.blade.php
│ │ └── profile.blade.php
│ └── errors/
│ ├── 404.blade.php
│ └── 500.blade.php
├── routes/
│ ├── api.php
│ └── web.php
├── .env.example
├── .gitignore
├── composer.json
├── IMPLEMENTATION.md
└── README.md
```

## 🔄 Flask to Laravel Mapping

| Flask Component | Laravel Equivalent |
|----------------|-------------------|
| Flask-Login | Laravel Auth + Livewire |
| Flask-SQLAlchemy | Eloquent ORM |
| Jinja2 Templates | Blade Templates + Livewire |
| Blueprint routes | Route definitions |
| @app.route decorators | Route::get/post |
| session | session() helper |
| flash() | session()->flash() |
| @login_required | Route::middleware('auth') |
| request.form | Livewire properties |
| render_template() | view() or Livewire render() |
| jsonify() | response()->json() |
| SQLAlchemy models | Eloquent models |

## 🚀 Next Steps for Production

To make this a production-ready application:

1. **Install via Composer**: Run full Laravel installation
2. **Environment**: Generate APP_KEY with `php artisan key:generate`
3. **Database**: Run migrations with `php artisan migrate --seed`
4. **Assets**: Set up Vite for asset compilation
5. **Middleware**: Add CSRF protection middleware
6. **Validation**: Add form request classes
7. **Testing**: Implement PHPUnit tests
8. **Caching**: Configure Redis/Memcached
9. **Queue**: Set up queue workers for PostHog events
10. **Deployment**: Configure for production server

## 📝 Notes

- This implementation uses inline CSS (matching Flask example) instead of Tailwind compilation
- Livewire provides reactivity without separate JavaScript files
- PostHog service is dependency-injected into components/controllers
- Manual error capture pattern matches Flask implementation
- Session-based burrito counter (same as Flask)
- Default admin account: admin@example.com / admin

## 🎓 Learning Resources

- [Laravel Documentation](https://laravel.com/docs)
- [Livewire Documentation](https://livewire.laravel.com)
- [PostHog PHP SDK](https://github.com/PostHog/posthog-php)
- [Eloquent ORM](https://laravel.com/docs/eloquent)

---

**Implementation Date**: January 2026
**Laravel Version**: 11.x
**Livewire Version**: 3.x
**PostHog PHP SDK**: 3.x
Loading
Loading