To create an operation use the make:operation artisan command:
php artisan make:operation some_name
The new operation's file will be placed in your /operations directory in the base path of your app.
Each operation file name contains a timestamp, which allows Laravel to determine the order of the operations. For example,
2025_04_02_121627_some_name.php
Asks For File Name
When calling the operations console command without passing a name in the name parameter, you will be asked for a name for the file.
php artisan make:operation
Creating an operation
┌ What should the operation be named? ─────────────────────────┐
│ E.g. activate articles │
└──────────────────────────────────────────────────────────────┘
Press Enter to autodetect
You can enter your own or simply press Enter to continue. In this case, automatic file name generation will be applied
Automatically Generate A File Name
If you do not specify the name attribute, then the file name will be generated automatically according to the rule:
php artisan make:operation
### When the git repository is found (`base_path('.git')` directory is exists) and HEAD branch name is 'qwerty'
# 2022_10_11_225116_qwerty.php
# 2022_10_11_225118_qwerty.php
# 2022_10_11_225227_qwerty.php
### When the git repository is not found (`base_path('.git')` directory doesn't exists).
# 2022_10_11_225116_auto.php
# 2022_10_11_225118_auto.php
# 2022_10_11_225227_auto.php
By default, the new operation class will contain the __invoke method, but you can easily replace it with public up name.
use DragonCode\LaravelDeployOperations\Operation;
return new class extends Operation {
public function __invoke(): void
{
// some code
}
};
use DragonCode\LaravelDeployOperations\Operation;
return new class extends Operation {
// called when `php artisan operations` running
public function __invoke(): void {}
// doesn't call when `php artisan migrate:rollback` running
// and any other commands to revert the operation.
public function down(): void {}
};
Dependency Injection
You can also use the dependency injection with __invoke, up and down methods:
use DragonCode\LaravelDeployOperations\Operation;
use Tests\Concerns\Some;
return new class extends Operation {
public function __invoke(Some $some): void
{
$value = $some->get('qwerty');
}
};
use DragonCode\LaravelDeployOperations\Operation;
use Tests\Concerns\Some;
return new class extends Operation {
public function up(Some $some): void
{
$value = $some->get('qwerty');
}
public function down(Some $some): void
{
$value = $some->get('qwerty');
}
};