Laravel Updater Documentation

website·Indexed 32 days ago

https://salahhusa9.com/laravel-updater

A package for Laravel applications that simplifies the process of updating the application. It supports GitHub as a repository source and provides functionality to run custom code before or after the update process.

Tokens
1.8K
Snippets
14
Records
19
Agent score
62%

What's inside Laravel Updater

  1. Install Laravel Updater

    Install the salahhusa9/laravel-updater package via Composer and publish the configuration file to your application.
    composer require salahhusa9/laravel-updater
    php artisan vendor:publish --tag="updater-config"
  2. Install laravel-updater via Composer

    Install the salahhusa9/laravel-updater package using Composer to enable menu building and management capabilities within your Laravel application.
    composer require salahhusa9/laravel-updater
  3. Implement custom update pipelines

    You can extend the update process by adding custom pipeline classes to the before_update_pipelines or after_update_pipelines configuration arrays. Every custom pipeline class must implement the Salahhusa9\Updater\Contracts\Pipeline contract, otherwise the updater will throw an exception.
  4. Execute custom logic before or after Laravel updates using pipelines

    To run custom functions before or after an update, create a pipeline class that implements the Salahhusa9\Updater\Contracts\Pipeline interface and register it in the configuration file under the before_update_pipelines or after_update_pipelines arrays.
    // In your config file
    return [
        'before_update_pipelines' => [
            \App\Pipelines\MyBeforeUpdatePipeline::class,
        ],
        'after_update_pipelines' => [
            \App\Pipelines\MyAfterUpdatePipeline::class,
        ],
    ];
  5. Configure Laravel Updater post-update actions

    You can configure the updater to automatically run migrations, seeders, and cache clearing commands after a successful update by modifying the config file. You can also define custom logic in the before_update_pipelines and after_update_pipelines arrays.
    return [
        'git_path' => null,
        'repository_source' => \Salahhusa9\Updater\RepositorySource\GithubRepository::class,
        'github_token' => env('GITHUB_TOKEN'),
        'github_username' => env('GITHUB_USERNAME'),
        'github_repository' => env('GITHUB_REPOSITORY'),
        'github_timeout' => 100,
    
        'maintenance_mode' => true, // Enables maintenance mode before update, disables after
        'maintenance_mode_secret' => env('MAINTENANCE_MODE_SECRET', false),
    
        'before_update_pipelines' => [],
    
        'migrate' => true, // run php artisan migrate
        'seeders' => [
            '\Database\Seeders\DatabaseSeeder::class',
        ],
        'cache:clear' => true,
        'view:clear' => true,
        'config:clear' => true,
        'route:clear' => true,
        'optimize' => true,
    
        'after_update_pipelines' => [],
    ];
  6. Automate database migrations and seeders after update

    The Laravel Updater allows you to trigger database migrations and specific seeders automatically after the update process is finished.
    'migrate' => true,
    'seeders' => [
        '\Database\Seeders\DatabaseSeeder::class',
    ],
  7. Configure or extend the repository source for Laravel Updater

    By default, Laravel Updater supports GitHub. Because the system is based on Git, other repository sources can be integrated. To change the repository source, update the repository_source value in the configuration file. If you are implementing a custom repository source, you must implement the Salahhusa9\Updater\Contracts\Repository contract.
  8. Configure maintenance mode during updates

    You can automatically enable maintenance mode before an update starts and disable it once the update is complete using the maintenance_mode and maintenance_mode_secret configuration keys.
    'maintenance_mode' => true,
    'maintenance_mode_secret' => env('MAINTENANCE_MODE_SECRET', false),
  9. Configure GitHub environment variables for Laravel Updater

    To enable the Laravel Updater, you must configure the following environment variables in your .env file to authenticate with GitHub and identify the target repository.
    GITHUB_TOKEN=ghp_1234567890
    GITHUB_USERNAME=salahhusa9
    GITHUB_REPOSITORY=laravel-updater
  10. Configure automatic cache and route clearing after update

    You can configure the updater to run standard Laravel artisan clear commands automatically after an update to ensure the application state is fresh.
    'cache:clear' => true,
    'view:clear' => true,
    'config:clear' => true,
    'route:clear' => true,
    'optimize' => true,