### Untitled No description -------------------------------- ### GET /admin/instances Source: https://context7.com/noorfikri/ta_saas/llms.txt Retrieves a list of all instances belonging to the authenticated user, including their status, associated URLs, and deployment information. ```APIDOC ## GET /admin/instances ### Description Retrieves all instances belonging to the authenticated user, showing status, URLs, and deployment information. ### Method GET ### Endpoint /admin/instances ### Response #### Success Response (200) - Returns a view 'instance.index' with a collection of instances. #### Response Example ```json [ { "id": 1, "name": "myapp", "aws_stack_id": "arn:aws:cloudformation:us-east-1:123456789012:stack/instance-1-myapp/abcdef12-3456-7890-abcd-ef1234567890", "aws_stack_name": "instance-1-myapp", "app_url": "ec2-54-123-45-67.compute-1.amazonaws.com", "status": "active", "message": "System is running properly.", "created_at": "2025-06-15T10:30:00.000000Z", "updated_at": "2025-06-15T10:45:00.000000Z" } ] ``` ``` -------------------------------- ### Get Stack Details Service in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Retrieves current AWS CloudFormation stack details, including status, outputs, and error messages. It requires App\Services\InstanceService. The method returns an array containing stack information or null if the stack is not found or an AWS API error occurs. ```php use App\Services\InstanceService; $service = new InstanceService(); $stackId = 'arn:aws:cloudformation:us-east-1:123456789:stack/instance-1-myapp/...' ; $details = $service->getStackDetails($stackId); // Returns array with AWS CloudFormation stack information: // [ // 'StackId' => 'arn:aws:cloudformation:...', // 'StackName' => 'instance-1-myapp', // 'StackStatus' => 'CREATE_COMPLETE', // 'StackStatusReason' => null, // 'CreationTime' => '2025-06-15T10:30:00Z', // 'Outputs' => [ // [ // 'OutputKey' => 'WebAppURL', // 'OutputValue' => 'ec2-54-123-45-67.compute-1.amazonaws.com' // ] // ] // ] // Possible StackStatus values: // - CREATE_IN_PROGRESS, CREATE_COMPLETE, CREATE_FAILED // - DELETE_IN_PROGRESS, DELETE_COMPLETE, DELETE_FAILED // - ROLLBACK_IN_PROGRESS, ROLLBACK_COMPLETE, ROLLBACK_FAILED // Returns null if stack not found or AWS API error ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### GET /admin/poll-instance-status Source: https://context7.com/noorfikri/ta_saas/llms.txt An AJAX endpoint designed to update the status of all pending instances by querying AWS CloudFormation for the latest stack status and returning the updated instance data. ```APIDOC ## GET /admin/poll-instance-status ### Description AJAX endpoint that updates all pending instances by querying AWS CloudFormation status and returns the latest instance data for the authenticated user. ### Method GET ### Endpoint /admin/poll-instance-status ### Response #### Success Response (200) - Returns a JSON object containing an array of updated instance data. #### Response Example ```json { "instances": [ { "id": 1, "name": "myapp", "status": "active", "app_url": "ec2-54-123-45-67.compute-1.amazonaws.com", "message": "System is running properly." } ] } ``` ### Internal Flow 1. Calls `updateInstanceStatuses()` for all instances with 'creating' or 'deleting' status. 2. Queries AWS CloudFormation `describeStacks` for each instance. 3. Updates the database based on the stack status: - `CREATE_COMPLETE`: Sets status to 'active' and extracts `app_url` from stack outputs. - `CREATE_FAILED`: Sets status to 'failed' and stores the error message. - `DELETE_COMPLETE`: Removes the database record. - `DELETE_FAILED`: Sets status to 'delete_failed' and stores the error message. ``` -------------------------------- ### Untitled No description -------------------------------- ### POST /admin/instances Source: https://context7.com/noorfikri/ta_saas/llms.txt Creates a new application instance by provisioning a complete AWS CloudFormation stack. The instance name must be unique across all users. ```APIDOC ## POST /admin/instances ### Description Creates a new application instance by provisioning a complete AWS CloudFormation stack with EC2, RDS, VPC, and networking resources. The instance name must be unique across all users. ### Method POST ### Endpoint /admin/instances ### Parameters #### Query Parameters - **name** (string) - Required - The desired name for the new instance. ### Request Body - **name** (string) - Required - Maximum 255 characters, must be unique. ### Request Example ```json { "name": "myapp" } ``` ### Response #### Success Response (Redirect) - Redirects to the instances.index page with a success message. - The instance is created with status: 'PENDING' -> 'creating'. #### Response Example ``` Redirect to /admin/instances with message: "Instance created successfully." ``` ### Database Record Example ```json { "name": "myapp", "aws_stack_name": "instance-1-myapp", "aws_stack_id": "arn:aws:cloudformation:us-east-1:123456789012:stack/instance-1-myapp/abcdef12-3456-7890-abcd-ef1234567890", "status": "creating", "message": "Instance provisioning is in progress..." } ``` ``` -------------------------------- ### Untitled No description -------------------------------- ### Environment Configuration for AWS Integration Source: https://context7.com/noorfikri/ta_saas/llms.txt Configuration settings for the application's environment, primarily focusing on AWS credentials and parameters for instance provisioning. It includes AWS access keys, region, EC2 key pair name, database connection details, and application settings. Also outlines the AWS CloudFormation resources that will be provisioned. ```bash # .env configuration # AWS Credentials - Required for CloudFormation operations AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY AWS_DEFAULT_REGION=us-east-1 # AWS EC2 Key Pair - Must exist in target region AWS_EC2_KEY_PAIR_NAME=my-keypair # Database Configuration DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=secret # Application APP_NAME="Instance Manager" APP_ENV=production APP_DEBUG=false APP_URL=https://manager.example.com # AWS CloudFormation will provision: # - EC2 t2.micro instances (Amazon Linux 2) # - RDS db.t3.micro MySQL databases # - VPC with public/private subnets in 2 AZs # - Security groups for web (80, 22) and database (3306) # Each instance gets unique: # - Database name: db{instance_id} # - Random 24-char password # - VPC with 10.0.0.0/16 CIDR # - Public access via EC2 public DNS ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Provision Instance Service in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Core service method that creates an AWS CloudFormation stack for a new instance. It requires App\Services\InstanceService and App\Models\Instance. The service creates a stack with specified parameters and updates the instance record with stack details upon success. It returns the Stack ID string or null on failure. ```php use App\Services\InstanceService; use App\Models\Instance; $instance = Instance::create([ 'name' => 'testapp', 'status' => 'PENDING' ]); $service = new InstanceService(); $stackId = $service->provisionInstance($instance); // Creates CloudFormation stack with: // - Stack name: 'instance-{id}-{slug-name}' // - Template: cloud/template/instance_create.yml // - Parameters: // - InstanceDBName: 'db{instance_id}' // - InstanceDBPassword: 24-character random string // - KeyName: from AWS_EC2_KEY_PAIR_NAME env variable // On success, updates instance: // - aws_stack_name: 'instance-1-testapp' // - aws_stack_id: 'arn:aws:cloudformation:...' // - status: 'creating' // - message: 'pembuatan sistem sedang berjalan...' // Returns: Stack ID string or null on failure ``` -------------------------------- ### Create Laravel Instance on AWS Source: https://context7.com/noorfikri/ta_saas/llms.txt Initiates the creation of a new application instance by provisioning a complete AWS CloudFormation stack. It requires a unique instance name and validates input before initiating the provisioning process. The instance status is initially set to 'PENDING'. ```php use App\Http\Controllers\InstanceController; use Illuminate\Http\Request; // POST /admin/instances // Request Body: name=myapp $request = new Request(['name' => 'myapp']); // Validation rules: // - name: required, string, max 255 characters, unique in instances table $controller = new InstanceController(new \App\Services\InstanceService()); $response = $controller->store($request); // Returns redirect to instances.index with success message // Instance created with status: 'PENDING' -> 'creating' // Database record includes: // - name: 'myapp' // - aws_stack_name: 'instance-1-myapp' // - aws_stack_id: 'arn:aws:cloudformation:...' // - status: 'creating' // - message: 'pembuatan sistem sedang berjalan...' ``` -------------------------------- ### List User Laravel Instances on AWS Source: https://context7.com/noorfikri/ta_saas/llms.txt Retrieves a list of all application instances associated with the authenticated user. The response includes key details such as instance name, AWS stack ID, application URL, deployment status, and relevant timestamps. This function is crucial for monitoring and managing deployed instances. ```php use App\Http\Controllers\InstanceController; // GET /admin/instances $controller = new InstanceController(new \App\Services\InstanceService()); $response = $controller->index(); // Returns view 'instance.index' with instances collection: // [ // { // "id": 1, // "name": "myapp", // "aws_stack_id": "arn:aws:cloudformation:us-east-1:123456789:stack/வுகளில்", // "aws_stack_name": "instance-1-myapp", // "app_url": "ec2-54-123-45-67.compute-1.amazonaws.com", // "status": "active", // "message": "Sistem telah berjalan dengan baik.", // "created_at": "2025-06-15T10:30:00.000000Z", // "updated_at": "2025-06-15T10:45:00.000000Z" // } // ] ``` -------------------------------- ### Upload File Service in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Handles file uploads, particularly for user profile pictures. It takes an UploadedFile instance, a base filename, and a target folder. The service automatically generates a unique filename using a timestamp and organizes files within the 'assets/uploaded/img/' directory. Dependencies include Symfony's HttpFoundation File component. ```php use App\Services\FileUploadService; use Symfony\Component\HttpFoundation\File\UploadedFile; // Example: Upload user profile picture $file = new UploadedFile( '/tmp/uploaded_photo.jpg', 'profile.jpg', 'image/jpeg', null, true ); $service = new FileUploadService(); $path = $service->uploadFile($file, 'john-doe', 'user'); // Uploads to: assets/uploaded/img/user/ // Filename format: user_john-doe_1718451234_profile.jpg // Returns: 'assets/uploaded/img/user/user_john-doe_1718451234_profile.jpg' // Parameters: // - $file: UploadedFile instance // - $filename: Base name for the file (user's name, instance name, etc.) // - $folder: Subfolder within assets/uploaded/img/ // File naming: {folder}_{filename}_{timestamp}_{original_name} ``` -------------------------------- ### Instance Model Eloquent ORM in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Defines an Eloquent model for application instances, tracking AWS infrastructure details. It supports creating, retrieving, and querying instances based on status. The model has a relationship with the User model and includes mass assignable fields and defined status values. ```php use App\Models\Instance; use App\Models\User; // Create instance $instance = Instance::create([ 'name' => 'production-app', 'aws_stack_id' => 'arn:aws:cloudformation:ப்புகளை', 'aws_stack_name' => 'instance-1-production-app', 'app_url' => 'ec2-54-123-45-67.compute-1.amazonaws.com', 'status' => 'active', 'message' => 'Sistem telah berjalan dengan baik.' ]); // Get instance owner $owner = $instance->user; // Returns User model with relationship // Query instances by status $activeInstances = Instance::where('status', 'active')->get(); $pendingInstances = Instance::whereIn('status', ['creating', 'PENDING'])->get(); // Mass assignable fields: // - name, aws_stack_id, aws_stack_name, app_url, status, message // Status values: // - PENDING: Initial state before CloudFormation submission // - creating: CloudFormation stack creation in progress // - active: Stack created, application running // - failed: Creation failed // - deleting: Stack deletion in progress // - delete_failed: Deletion failed ``` -------------------------------- ### Update Instance Statuses Service in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt A background process that synchronizes database instance states with AWS CloudFormation stack statuses for instances in transitional states. It requires App\Services\InstanceService. The method queries AWS for stack status and updates the database accordingly, including setting the instance status and extracting output URLs. It has no return value, performing direct database updates. ```php use App\Services\InstanceService; $service = new InstanceService(); $service->updateInstanceStatuses(); // Processes all instances with status 'creating' or 'deleting' // For each instance: // 1. Query AWS CloudFormation stack status // 2. Update database based on status: // Status mapping: // - CREATE_COMPLETE -> // status: 'active' // app_url: extracted from stack outputs 'WebAppURL' // message: 'Sistem telah berjalan dengan baik.' // - CREATE_FAILED / ROLLBACK_COMPLETE / ROLLBACK_FAILED -> // status: 'failed' // message: AWS error reason // - DELETE_COMPLETE -> // Deletes database record // - DELETE_FAILED -> // status: 'delete_failed' // message: AWS error reason // - Other statuses (IN_PROGRESS) -> // No change, logs current status // No return value, updates performed directly on database ``` -------------------------------- ### Untitled No description -------------------------------- ### User Model Eloquent ORM with Relationships in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Represents an authenticated user with capabilities for tracking owned instances and API authentication via Laravel Sanctum. It supports creating users, retrieving their associated instances, querying instances by status, and counting the number of instances. ```php use App\Models\User; use Illuminate\Support\Facades\Hash; // Create user $user = User::create([ 'name' => 'Jane Smith', 'email' => 'jane@example.com', 'password' => Hash::make('secret123') ]); // Get user's instances $instances = $user->instances; // Returns collection of Instance models // Query active instances for user $activeInstances = $user->instances() ->where('status', 'active') ->get(); // Count user's instances $count = $user->instances()->count(); // Mass assignable fields: name, email, password // Hidden fields: password, remember_token // Uses Laravel Sanctum for API authentication: // - HasApiTokens trait enables personal access token generation // - Tokens used for API routes: /api/user endpoint ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### DELETE /admin/instances/{instance} Source: https://context7.com/noorfikri/ta_saas/llms.txt Deletes an instance by initiating the AWS CloudFormation stack deletion process, which removes all associated AWS resources. ```APIDOC ## DELETE /admin/instances/{instance} ### Description Deletes an instance by triggering AWS CloudFormation stack deletion, which removes all associated AWS resources including EC2, RDS, VPC, and networking components. ### Method DELETE ### Endpoint /admin/instances/{instance} ### Parameters #### Path Parameters - **instance** (integer|string) - Required - The ID or identifier of the instance to delete. ### Response #### Success Response (Redirect) - Redirects to the instances list page with a success message indicating the deletion process has started. #### Response Example ``` Redirect to /admin/instances with message: "Deletion of system 'myapp' is in progress." ``` ### Behavior - **Authorization**: User must own the instance. - **If `aws_stack_id` exists**: Sets instance status to 'deleting' and initiates CloudFormation stack deletion. A background process monitors the deletion status. - **If `aws_stack_id` does not exist**: Deletes the database record immediately. ``` -------------------------------- ### Deprovision Instance Service in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Triggers the deletion of an AWS CloudFormation stack, removing all provisioned infrastructure resources. This service requires App\Services\InstanceService. It calls CloudFormation->deleteStack() and returns true on success or false on AWS API failure. Note that deletion is asynchronous. ```php use App\Services\InstanceService; $service = new InstanceService(); $stackId = 'arn:aws:cloudformation:us-east-1:123456789:stack/instance-1-myapp/...' ; $result = $service->deprovisionInstance($stackId); // Calls CloudFormation->deleteStack() // Stack deletion cascades to all resources: // - EC2 Instance // - RDS Database // - VPC, Subnets, Route Tables // - Security Groups // - Internet Gateway // Returns: true on success, false on AWS API failure // Note: Actual deletion is asynchronous, monitor via updateInstanceStatuses() ``` -------------------------------- ### Untitled No description -------------------------------- ### Update User Profile in PHP Source: https://context7.com/noorfikri/ta_saas/llms.txt Updates the authenticated user's profile information such as name, email, contact details, and profile picture. It handles optional file uploads for the profile picture. Dependencies include App\Http\Controllers\UserController, App\Models\User, and Illuminate\Http\Request. It returns a redirect to 'admin/profile' with a success message. ```php use App\Http\Controllers\UserController; use App\Models\User; use Illuminate\Http\Request; // POST /admin/users/updateProfile/{user} $user = User::find(1); $request = new Request([ 'name' => 'John Doe', 'email' => 'john@example.com', 'contact_number' => '+1234567890', 'address' => '123 Main St' ]); // Optional file upload: // $request->files->add(['image' => $uploadedFile]); $controller = new UserController(); $response = $controller->update($request, $user); // If image provided: // - Uploads to assets/uploaded/img/user/ // - Filename format: user_John Doe_1234567890_original.jpg // - Sets user->profile_picture field // Returns redirect to 'admin/profile' with success message ``` -------------------------------- ### Delete Laravel Instance on AWS Source: https://context7.com/noorfikri/ta_saas/llms.txt Deletes an application instance by initiating the deletion of its associated AWS CloudFormation stack. This action removes all related AWS resources. The function includes authorization checks and handles instances with or without an existing AWS stack ID. ```php use App\Http\Controllers\InstanceController; use App\Models\Instance; // DELETE /admin/instances/{instance} $instance = Instance::find(1); $controller = new InstanceController(new \App\Services\InstanceService()); $response = $controller->destroy($instance); // Authorization check: User must own the instance // If instance has aws_stack_id: // - Sets status to 'deleting' // - Calls CloudFormation deleteStack // - Background process monitors deletion // If no aws_stack_id: // - Deletes database record immediately // Returns redirect with message: // "Penghapusan sistem untuk sistem 'myapp' sedang berjalan." ``` -------------------------------- ### Poll Laravel Instance Status on AWS Source: https://context7.com/noorfikri/ta_saas/llms.txt An AJAX endpoint to update the status of pending instances by querying AWS CloudFormation. It retrieves the latest instance data, including status and application URL, and returns it to the user. The process involves updating database records based on the CloudFormation stack status. ```php use App\Http\Controllers\InstanceController; // GET /admin/poll-instance-status $controller = new InstanceController(new \App\Services\InstanceService()); $response = $controller->status(); // Internal flow: // 1. Calls updateInstanceStatuses() on all 'creating' or 'deleting' instances // 2. Queries AWS CloudFormation describeStacks for each // 3. Updates database based on stack status: // - CREATE_COMPLETE -> status: 'active', extracts app_url from outputs // - CREATE_FAILED -> status: 'failed', stores error message // - DELETE_COMPLETE -> removes database record // - DELETE_FAILED -> status: 'delete_failed', stores error message // Returns JSON: // { // "instances": [ // { // "id": 1, // "name": "myapp", // "status": "active", // "app_url": "ec2-54-123-45-67.compute-1.amazonaws.com", // "message": "Sistem telah berjalan dengan baik." // } // ] // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.