• Reading time ~ 1 min
  • 15.03.2023

You can use the One Time Operations package for Laravel to run code that should only run once after deployment. With this package, you can create operation classes that can be executed automatically using a provided Artisan command. Similar to migrations, they only get processed once and then never run again.

When you generate classes using this package's operations:make command, they use anonymous classes extending the OneTimeOperation class:

use TimoKoerber\LaravelOneTimeOperations\OneTimeOperation;

return new class extends OneTimeOperation
{
    /**
     * Determine if the operation is being processed asyncronously.
     */
    protected bool $async = true;

    /**
     * Process the operation.
     */
    public function process(): void
    {
        //
    }
};

Using this package, you could update specific data after deploying new code, seed data after a migration, or run any type of code that you only need to execute once in tandem with a deployment. This package also provides the ability to test operations (run them multiple times without flagging them).

If you'd like to learn more about this package, you can check out the source code and readme docs on GitHub

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297