SaaS Controllers Featured

SaaS Platform Controllers Reference

Complete reference for all Laravel controllers in the SaaS platform including methods, features, and usage examples.

196 views
Updated 3 hours ago
# SaaS Platform Controllers - Complete Reference ## Core Application Controllers ### DashboardController **Purpose:** Main application dashboard and overview **Key Methods:** - `index()`: Main dashboard with metrics, recent activity, and quick actions - `stats()`: Real-time statistics API endpoint - `overview()`: Tenant overview with session summaries **Features:** - Real-time activity feeds - Project progress indicators - Team productivity metrics - Quick action buttons ### TenantBaseController **Purpose:** Base class providing tenant context for all tenant-aware controllers **Key Features:** ```php protected function initializeTenant() { $this->currentTenant = tenant(); $this->currentUser = auth()->user(); // Validate tenant access if (!$this->currentTenant || !$this->currentUser->canAccessTenant($this->currentTenant)) { abort(403, 'Tenant access denied'); } } ``` **Inherited By:** All tenant-specific controllers ## Project Management ### ProjectController **Purpose:** Complete project lifecycle management **Key Methods:** - `index()`: Project listing with filters and search - `create()`: Project creation form - `store()`: Project creation with validation - `show($project)`: Detailed project view with tasks and team - `edit($project)`: Project editing interface - `update($project)`: Project updates with change tracking - `destroy($project)`: Soft delete with confirmation **Features:** - Team member assignment - Project templates - Progress tracking - Budget management - File attachments ### TaskController **Purpose:** Kanban-style task management **Key Methods:** ```php public function index() { $tasks = Task::with(['assignee', 'project', 'creator']) ->where('project_id', $projectId) ->orderBy('sort_order') ->get() ->groupBy('status'); return view('tasks.kanban', compact('tasks')); } public function updateStatus(Task $task, Request $request) { $task->update([ 'status' => $request->status, 'sort_order' => $request->sort_order ]); return response()->json(['success' => true]); } ``` **Features:** - Drag-and-drop interface - Status columns (To Do, In Progress, Review, Done) - Task assignment and due dates - Comment system - Time tracking integration ## Time Tracking System ### TimeTrackController **Purpose:** Comprehensive time tracking and session management **Key Methods:** - `index()`: Time tracking dashboard with active sessions - `sessions()`: Session history with filters - `reports()`: Detailed time reports with charts - `export()`: Export time data to CSV/PDF **Session Management:** ```php public function startSession(Request $request) { $session = TimeSession::create([ 'user_id' => auth()->id(), 'project_id' => $request->project_id, 'started_at' => now(), 'type' => 'work' ]); return response()->json(['session_id' => $session->id]); } ``` ### SessionLogController **Purpose:** Desktop app integration and activity processing **Key Methods:** - `store()`: Process incoming activity data from desktop app - `screenshots()`: Handle screenshot uploads - `analysis()`: Generate productivity insights **Data Processing:** ```php public function processCapture(Request $request) { $captureData = $request->validate([ 'start_time' => 'required|date', 'end_time' => 'required|date', 'key_count' => 'required|integer', 'click_count' => 'required|integer', 'screenshots' => 'array' ]); // Process and store activity data $this->storeActivityData($captureData); return response()->json(['status' => 'success']); } ``` ## User Management ### UserController **Purpose:** User management within tenant context **Key Methods:** - `index()`: User listing with roles and permissions - `create()`: User invitation system - `store()`: User creation with email invitations - `edit($user)`: User profile editing - `update($user)`: Profile updates with validation - `destroy($user)`: User removal with data handling **Role Management:** ```php public function assignRole(User $user, Request $request) { $user->syncRoles($request->roles); // Log role change activity() ->performedOn($user) ->log('Roles updated'); return redirect()->back()->with('success', 'Roles updated'); } ``` ### TeamController **Purpose:** Team organization and collaboration **Key Methods:** - `index()`: Team overview with member statistics - `create()`: Team creation interface - `members($team)`: Team member management - `projects($team)`: Team project assignments ## Communication System ### MessageController **Purpose:** Real-time messaging and notifications **Key Methods:** ```php public function store(Request $request) { $message = Message::create([ 'sender_id' => auth()->id(), 'recipient_id' => $request->recipient_id, 'content' => $request->content, 'type' => $request->type ?? 'text' ]); // Send real-time notification broadcast(new MessageSent($message)); return response()->json(['message' => $message]); } ``` **Features:** - File attachments - Real-time notifications - Message threading - Read receipts ## Subscription Management ### SubscriptionController **Purpose:** Stripe integration and billing management **Key Methods:** - `index()`: Current subscription overview - `plans()`: Available plans with feature comparison - `subscribe(Plan $plan)`: Plan subscription with Stripe - `cancel()`: Subscription cancellation - `resume()`: Subscription resumption - `webhooks()`: Stripe webhook processing **Stripe Integration:** ```php public function subscribe(Request $request) { $user = auth()->user(); $plan = Plan::findOrFail($request->plan_id); $subscription = $user->newSubscription('default', $plan->stripe_price_id) ->create($request->payment_method); // Update tenant features $this->updateTenantFeatures($subscription, $plan); return redirect()->route('dashboard') ->with('success', 'Subscription activated!'); } ``` ### FeaturesController **Purpose:** Feature management and access control **Key Methods:** - `index()`: Feature overview with availability - `show($feature)`: Detailed feature information - `comparison()`: API endpoint for feature comparison **Feature Checking:** ```php public function hasFeature($featureSlug) { $tenant = tenant(); return $tenant->subscription ->items() ->whereHas('price.features', function($q) use ($featureSlug) { $q->where('slug', $featureSlug); }) ->exists(); } ``` ## Administrative Controllers ### System\DashboardController **Purpose:** System-wide administration **Key Methods:** - `index()`: Admin dashboard with system metrics - `tenants()`: Tenant management interface - `subscriptions()`: Subscription analytics - `loginAsTenant($tenantId)`: Tenant impersonation ### System\PlanController **Purpose:** Subscription plan management **Key Methods:** - `index()`: Plan listing and management - `create()`: New plan creation - `manageFeatures($plan)`: Feature assignment interface - `subscribers($plan)`: Plan subscriber analytics ## API Controllers ### Api\DesktopController **Purpose:** Desktop application API endpoints **Authentication:** ```php public function authenticate(Request $request) { $credentials = $request->validate([ 'email' => 'required|email', 'password' => 'required' ]); if (Auth::attempt($credentials)) { $user = auth()->user(); $token = $user->createToken('desktop-app')->plainTextToken; return response()->json([ 'token' => $token, 'user' => $user, 'tenants' => $user->tenants ]); } return response()->json(['error' => 'Invalid credentials'], 401); } ``` ## Middleware Integration ### Custom Middleware - `CheckSubscriptionAccess`: Validates subscription status - `CheckFeatureAccess`: Feature-based route protection - `CheckTenantSuspension`: Blocks suspended tenants - `BlockedIPMiddleware`: IP-based security ### Usage Example: ```php Route::middleware(['auth', 'tenant', 'feature:advanced_reporting']) ->get('/reports/advanced', [ReportsController::class, 'advanced']); ``` This comprehensive controller documentation provides complete coverage of all major system components and their interactions within the WorkPulse Solutions platform.

Was this article helpful?

Contents
Ready to get started?

Join WorkPulse and start managing your projects more efficiently.