SaaS PHP Documentation

website·Indexed 29 days ago

https://saasphp.com/

A Laravel starter kit for subscription products featuring a customer-facing React and Inertia app, a Filament 5 admin panel, and Stripe integration for billing. Includes documentation on installation, project architecture, authentication via Laravel Fortify, and deployment checklists.

Tokens
6.4K
Snippets
16
Records
66
Agent score
50%

What's inside SaaS PHP

  1. Overview of the SaaSPHP Admin Panel

    The admin panel is powered by Filament 5 and is mounted at /admin. It is designed for internal operations rather than the customer billing experience. Primary use cases include user administration, role and permission management, subscription plan management, customer subscription oversight, and site-wide settings.
  2. Understand the SaaSPHP project directory structure

    The application is organized into two main user experiences (Customer and Admin) with shared domain logic. Key directories include:

    • resources/js/pages: Customer UI components
    • app/Filament: Admin UI configuration
    • app/Models: Domain models
    • app/Actions: Business actions
    • app/Services: Service-layer helpers
    • routes/: Route definitions
    • database/: Database schema and seed data
  3. Manage database-backed settings via Admin UI

    SaaS PHP provides a database-backed settings layer stored in the settings table, allowing non-developers to change behavior via the admin settings page (/admin/settings). These settings are grouped into categories such as siteSettings, socialProviders, paymentGateways, featuresSettings, emailSettings, and smsSettings.
  4. Understand the frontend styling stack

    The application uses Tailwind CSS 4 for styling. Styles are implemented using utility classes within React components. Custom admin theme CSS is provided for Filament.
  5. SaaS PHP Architecture Overview

    SaaS PHP is a Laravel starter kit designed for single-product subscription SaaS applications. It consists of four primary surfaces:

    • Customer App: Built with Inertia and React for onboarding, pricing, checkout, subscriptions, invoices, and account settings.
    • Admin Panel: A Filament-powered interface located at /admin for managing users, roles, permissions, plans, subscriptions, and site settings.
    • Settings Layer: A database-backed system (stored in the settings table) that loads dynamically into runtime configuration.
    • Billing System: Stripe-powered flows managing subscription lifecycles and webhook processing.
  6. Configure Social Login providers

    The system supports Google, Microsoft, Yahoo, GitHub, and Twitter. Provider credentials are loaded dynamically from the settings table by LoadOAuthConfig.

    Routes:

    • GET /login/{provider}
    • GET /auth/{provider}/callback

    Business Rules:

    • The provider must return a verified email address.
    • Local accounts are not automatically linked by email matching.
    • Social identities are stored using oauth_provider and oauth_provider_id upon account creation.
  7. Manage default settings and seed data

    Default settings, including their initial values, groups, and expected data types, are defined in the config/saasphp-data.php file. These defaults are inserted into the database by the DatabaseSeeder during the seeding process.
    // Default settings are defined here:
    config/saasphp-data.php
  8. Implement authorization and access control

    SaaSPHP uses a layered authorization approach:

    • Authentication Flows: Handled by Laravel Fortify.
    • Access Policies: Located in app/Policies.
    • Roles and Permissions: Managed via Spatie Permission.
    • Admin Permissions: Integrated with Filament Shield.
    • Isolation: Middleware is used to prevent privileged staff accounts from accessing user-only account areas.
  9. Install and initialize a new SaaSphp project

    SaaSphp is a standard Laravel application with a React and Inertia frontend. To create a new project, use Composer to pull the repository and then use Laravel Sail to set up the environment, run migrations, seed the database, and install frontend dependencies. The installation process automatically copies the .env.example file to .env and generates the application key.
    composer create-project saasphp/saasphp saasphp
    cd saasphp
    
    ./vendor/bin/sail up -d
    ./vendor/bin/sail artisan migrate
    ./vendor/bin/sail artisan db:seed
    ./vendor/bin/sail npm install
  10. Handle admin user impersonation

    The application supports admin impersonation for support operations. To end an impersonation session, use the following route:

    • GET /impersonate/leave

    While impersonation is active, the BlockImpersonatedAccess middleware prevents access to sensitive customer settings.

  11. Prepare a Laravel SaaS application for production deployment

    Deploying this project follows standard Laravel application procedures with an additional frontend build step. Ensure the following steps are completed for a successful go-live:

    1. Configure environment variables: Set APP_ENV, APP_URL, database connections, cache store, and queue configuration.
    2. Security: Set the APP_KEY.
    3. Database: Run migrations and seed only the essential production data.
    4. Frontend: Build assets using npm run build.
    5. Background Tasks: Configure a supervised queue worker (do not use queue:listen in production).
    6. Stripe: Configure webhook delivery to the POST /webhooks/stripe endpoint.
    7. Cleanup: Replace any seeded development users and passwords.
    npm run build
  12. Develop for the Customer application surface

    The customer-facing side of the application is built using Inertia and React. It covers the Welcome page, Dashboard, Auth flows, Settings, and Billing. Routes are organized into specific files:

    • routes/web.php
    • routes/auth.php
    • routes/settings.php
    • routes/billing.php