PHP code example of sabitahmadumid / laravel-launchpad

1. Go to this page and download the library: Download sabitahmadumid/laravel-launchpad library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sabitahmadumid / laravel-launchpad example snippets


   // config/launchpad.php
   'language' => [
       'available' => [
           'en' => ['name' => 'English', 'native' => 'English', 'flag' => 'πŸ‡ΊπŸ‡Έ'],
           'es' => ['name' => 'Spanish', 'native' => 'Español', 'flag' => 'οΏ½οΏ½'],
           'fr' => ['name' => 'French', 'native' => 'Français', 'flag' => 'οΏ½οΏ½'],
           // Add any language you want
       ],
   ],
   

'language' => [
    'default' => 'en',                              // Default language
    'auto_detect' => true,                          // Auto-detect from browser
    'session_key' => 'launchpad_language',          // Session storage key
    'switcher' => [
        'enabled' => true,                          // Show language switcher
        'show_flags' => true,                       // Show flag icons
        'show_native_names' => true,                // Show native language names
        'position' => 'top-right',                  // Switcher position
    ],
],

// Get language service
$languageService = app(\SabitAhmad\LaravelLaunchpad\Services\LanguageService::class);

// Switch language
$languageService->setLanguage('es'); // or any available language

// Get current language
$current = $languageService->getCurrentLanguage();

// Check available languages
$available = $languageService->getAvailableLanguages();

// Check if RTL
$isRtl = $languageService->isRtl();

use SabitAhmad\LaravelLaunchpad\Services\LicenseService;

$licenseService = app(LicenseService::class);

// Simple boolean check - handles everything automatically
if ($licenseService->isLicenseVerified()) {
    // License is valid, proceed with functionality
    return view('premium-feature');
} else {
    // License is invalid or missing
    return redirect()->route('license.



namespace App\Services;

use SabitAhmad\LaravelLaunchpad\Contracts\LicenseValidatorInterface;
use Illuminate\Support\Facades\Http;

class EnvatoLicenseValidator implements LicenseValidatorInterface
{
    public function validate(string $licenseKey, array $options = []): array
    {
        // Development bypass for local testing
        if (app()->environment(['local', 'testing'])) {
            $devKeys = ['ENVATO-DEV-BYPASS', 'dev-license-key', 'envato-test-key'];
            if (in_array($licenseKey, $devKeys)) {
                return [
                    'valid' => true, 
                    'message' => 'Development license bypass'
                ];
            }
        }

        // Validate with Envato API
        try {
            $response = $this->validateWithEnvato($licenseKey);
            
            if ($response['valid']) {
                return [
                    'valid' => true,
                    'message' => 'Valid Envato purchase code',
                    'data' => $response['data']
                ];
            }

            return [
                'valid' => false,
                'message' => $response['message'] ?? 'Invalid Envato purchase code'
            ];

        } catch (\Exception $e) {
            return [
                'valid' => false,
                'message' => 'Envato validation error: ' . $e->getMessage()
            ];
        }
    }

    private function validateWithEnvato(string $purchaseCode): array
    {
        $token = env('ENVATO_API_TOKEN');
        
        if (!$token) {
            throw new \Exception('Envato API token not configured');
        }

        $response = Http::withHeaders([
            'Authorization' => 'Bearer ' . $token,
            'User-Agent' => config('app.name', 'Laravel Application')
        ])->timeout(30)->get("https://api.envato.com/v3/market/author/sale?code={$purchaseCode}");

        if ($response->successful()) {
            $data = $response->json();
            return [
                'valid' => true, 
                'data' => [
                    'item_id' => $data['item']['id'] ?? null,
                    'item_name' => $data['item']['name'] ?? null,
                    'buyer' => $data['buyer'] ?? null,
                    'purchase_date' => $data['sold_at'] ?? null,
                ]
            ];
        }

        $error = $response->json();
        return [
            'valid' => false, 
            'message' => $error['description'] ?? 'Invalid purchase code'
        ];
    }
}



namespace App\Services;

use SabitAhmad\LaravelLaunchpad\Contracts\LicenseValidatorInterface;
use Illuminate\Support\Facades\Http;

class CustomServerLicenseValidator implements LicenseValidatorInterface
{
    public function validate(string $licenseKey, array $options = []): array
    {
        // Development bypass
        if (app()->environment(['local', 'testing'])) {
            $devKeys = ['CUSTOM-DEV-KEY', 'dev-license-key', 'server-test-key'];
            if (in_array($licenseKey, $devKeys)) {
                return [
                    'valid' => true, 
                    'message' => 'Development license bypass'
                ];
            }
        }

        $serverUrl = config('launchpad.license.server_url');
        
        if (!$serverUrl) {
            return [
                'valid' => false,
                'message' => 'License server URL not configured'
            ];
        }

        try {
            $response = Http::timeout(30)->post($serverUrl, [
                'license_key' => $licenseKey,
                'domain' => request()->getHost(),
                'product' => config('app.name'),
                'version' => config('launchpad.update.current_version'),
                'ip' => request()->ip(),
            ]);

            if ($response->successful()) {
                $data = $response->json();
                
                return [
                    'valid' => $data['valid'] ?? false,
                    'message' => $data['message'] ?? 'License validation completed',
                    'data' => $data['license_data'] ?? []
                ];
            }

            return [
                'valid' => false,
                'message' => 'License server error: HTTP ' . $response->status()
            ];

        } catch (\Exception $e) {
            return [
                'valid' => false,
                'message' => 'Connection error: ' . $e->getMessage()
            ];
        }
    }
}

return [
    'installation' => [
        'enabled' => false, // Set to true for new installations
        'route_prefix' => 'install',
        'route_middleware' => ['web'],
        'completed_file' => storage_path('app/installed.lock'),
    ],
    
    'update' => [
        'enabled' => false, // Set to true for updates
        'route_prefix' => 'update',
        'route_middleware' => ['web'],
        'version_file' => storage_path('app/version.lock'),
        'current_version' => '1.0.0', // Update this for new versions
    ],
    
    'license' => [
        // License key from environment
        'key' => env('LAUNCHPAD_LICENSE_KEY'),
        
        // Custom validator class (SimpleLicenseValidator is recommended)
        'validator_class' => env('LAUNCHPAD_VALIDATOR_CLASS', 'App\\Services\\SimpleLicenseValidator'),
        
        // Request timeout for license validation
        'timeout' => env('LAUNCHPAD_LICENSE_TIMEOUT', 30),
        
        // Cache duration for license validation results (in seconds)
        'cache_duration' => env('LAUNCHPAD_LICENSE_CACHE', 3600),
        
        // Development bypass options (only works in local/testing environments)
        'development' => [
            'accept_dev_keys' => env('LAUNCHPAD_ACCEPT_DEV_KEYS', true),
            'dev_keys' => [
                'dev-license-key',
                'local-development', 
                'testing-license',
                'bypass-license-check',
            ],
        ],
    ],
    
    'ui' => [
        'app_name' => env('APP_NAME', 'Laravel Application'), // Only env dependency
        'logo_url' => null, // Optional logo URL
        'primary_color' => '#3B82F6',
    ],
    
    '      ],
        'cache_clear' => true,  // Automatically clear cache after updates
        'config_cache' => true, // Automatically cache config after updates
    ],
    
    'admin' => [
        'enabled' => true,
        'model' => 'App\\Models\\User',
        'fields' => [
            'name' => [
                'type' => 'text',
                'label' => 'Full Name',
                '

'additional_fields' => [
    [
        'name' => 'company',
        'label' => 'Company Name',
        'type' => 'text',
        '      'type' => 'tel',
        '

// config/launchpad.php - Database configuration
'database' => [
    'import_options' => [
        'dump_file' => [
            'enabled' => true,  // βœ… Enable SQL dump import
            'path' => database_path('dump.sql'),
            'description' => 'Import initial database dump',
        ],
        'migrations' => [
            'enabled' => false, // ❌ Disable migrations when using dump
            'description' => 'Run database migrations',
        ],
        'seeders' => [
            'enabled' => true,  // βœ… Optional: Additional seed data
            'description' => 'Run database seeders',
        ],
    ],
],

// config/launchpad.php - Database configuration
'database' => [
    'import_options' => [
        'dump_file' => [
            'enabled' => false, // ❌ Disable dump when using migrations
            'path' => database_path('dump.sql'),
            'description' => 'Import initial database dump',
        ],
        'migrations' => [
            'enabled' => true,  // βœ… Enable Laravel migrations
            'description' => 'Run database migrations',
        ],
        'seeders' => [
            'enabled' => true,  // βœ… Run database seeders after migrations
            'description' => 'Run database seeders',
        ],
    ],
],

// config/launchpad.php - Update configuration
'update_options' => [
    // For SQL-based updates
    'dump_file' => [
        'enabled' => true,  // βœ… Use update SQL file
        'path' => database_path('updates/update.sql'),
        'description' => 'Import update database dump',
    ],
    'migrations' => [
        'enabled' => false, // ❌ Disable when using dump
        'description' => 'Run update migrations',
    ],
    
    // OR for migration-based updates
    'dump_file' => [
        'enabled' => false, // ❌ Disable when using migrations
        'path' => database_path('updates/update.sql'),
        'description' => 'Import update database dump',
    ],
    'migrations' => [
        'enabled' => true,  // βœ… Use Laravel migrations
        'description' => 'Run update migrations',
    ],
],

// Uses SQL dump for complex product catalogs and configurations
'import_options' => [
    'dump_file' => ['enabled' => true, 'path' => database_path('ecommerce.sql')],
    'migrations' => ['enabled' => false],
    'seeders' => ['enabled' => true], // Additional demo products
],

// Uses migrations for clean, version-controlled structure
'import_options' => [
    'dump_file' => ['enabled' => false],
    'migrations' => ['enabled' => true],
    'seeders' => ['enabled' => true], // Demo contacts and companies
],

// Uses SQL dump to preserve existing database structure
'import_options' => [
    'dump_file' => ['enabled' => true, 'path' => database_path('legacy.sql')],
    'migrations' => ['enabled' => false],
    'seeders' => ['enabled' => false], // Data already in dump
],

// config/launchpad.php
'installation' => [
    'enabled' => true,  // βœ… Enable installation wizard
],
'update' => [
    'enabled' => false, // ❌ Disable update wizard
],

// Configure automatic database setup
'importOptions' => [
    'dump_file' => ['enabled' => true, 'path' => database_path('dump.sql')],
    'migrations' => ['enabled' => false], // Choose one method
    'seeders' => ['enabled' => true],
],

// config/launchpad.php
'installation' => [
    'enabled' => false, // ❌ Disable installation wizard
],
'update' => [
    'enabled' => true,  // βœ… Enable update wizard
    'current_version' => '2.0.0', // Your new version
],

// Configure automatic update operations
'update_options' => [
    'dump_file' => ['enabled' => true, 'path' => database_path('updates/update.sql')],
    'migrations' => ['enabled' => false], // Choose one method
    'cache_clear' => true,
    'config_cache' => true,
],

// For first release v1.0.0
'installation' => ['enabled' => true],
'update' => ['enabled' => false],

// For update release
'installation' => ['enabled' => false],
'update' => [
    'enabled' => true,
    'current_version' => '1.1.0',
],

// ⚠️ DO NOT DO THIS - Will cause conflicts!
'installation' => ['enabled' => true],  // ❌ BAD
'update' => ['enabled' => true],        // ❌ BAD

// config/launchpad.php - Direct configuration management
'installation' => ['enabled' => true],  // No env dependency
'update' => ['enabled' => false],       // No env dependency
'license' => ['enabled' => true],       // No env dependency
'update' => ['current_version' => '1.1.0'], // No env dependency

'ui' => [
    'app_name' => env('APP_NAME', 'Laravel Application'), // Only env dependency
],

use SabitAhmad\LaravelLaunchpad\Services\InstallationService;
use SabitAhmad\LaravelLaunchpad\Services\LicenseService;
use SabitAhmad\LaravelLaunchpad\Services\DatabaseService;

// Check if application is installed
$installationService = app(InstallationService::class);
if ($installationService->isInstalled()) {
    // Application is installed
}

// Validate license
$licenseService = app(LicenseService::class);
$isValid = $licenseService->validateLicense('your-license-key');

// Test database connection
$databaseService = app(DatabaseService::class);
$canConnect = $databaseService->testConnection([
    'host' => 'localhost',
    'database' => 'your_db',
    'username' => 'user',
    'password' => 'pass',
]);

// ❌ BAD - Will cause route conflicts!
'installation' => ['enabled' => true],
'update' => ['enabled' => true],

// βœ… GOOD - Choose ONE mode
'installation' => ['enabled' => true],  // For new installs
'update' => ['enabled' => false],

// ❌ BAD - Will cause database conflicts!
'importOptions' => [
    'dump_file' => ['enabled' => true],
    'migrations' => ['enabled' => true], // ❌ Conflict
],

// βœ… GOOD - Choose ONE database method
'importOptions' => [
    'dump_file' => ['enabled' => true],
    'migrations' => ['enabled' => false],
],
bash
php artisan vendor:publish --tag="laravel-launchpad-config"
bash
php artisan vendor:publish --tag="laravel-launchpad-views"
bash
php artisan vendor:publish --tag="laravel-launchpad-lang"
bash
php artisan launchpad:publish-lang

resources/lang/vendor/launchpad/
β”œβ”€β”€ en/
β”‚   β”œβ”€β”€ common.php      # Common UI elements
β”‚   β”œβ”€β”€ install.php     # Installation wizard
β”‚   └── update.php      # Update wizard
└── {lang}/
    β”œβ”€β”€ common.php      # Translated UI elements
    β”œβ”€β”€ install.php     # Translated installation wizard
    └── update.php      # Translated update wizard
bash
   php artisan launchpad:publish-lang
   
bash
   php artisan launchpad:license-stub
   
bash
   php artisan launchpad:license disable
   
bash
php artisan config:clear
bash
php artisan config:clear
php artisan cache:clear
php artisan route:clear