Skip to content

Commit e0314bc

Browse files
author
Andrey Helldar
authored
Merge pull request #33 from TheDragonCode/2.x
Added the `artisan` method
2 parents 8d8c163 + e8b16c8 commit e0314bc

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ Or manually update `require` block of `composer.json` and run `composer update`.
2323
```json
2424
{
2525
"require": {
26-
"dragon-code/laravel-migration-actions": "^2.2"
26+
"dragon-code/laravel-migration-actions": "^2.3"
2727
}
2828
}
2929
```
3030

31-
### Upgrade from `dragon-code/laravel-actions`
31+
### Upgrade From `dragon-code/laravel-actions`
3232

3333
1. In your `composer.json` file, replace `dragon-code/laravel-actions` with `dragon-code/laravel-migration-actions`.
3434
3. Run the `command composer` update.
3535
4. Profit!
3636

37-
### Upgrade from `andrey-helldar/laravel-migration-actions`
37+
### Upgrade From `andrey-helldar/laravel-migration-actions`
3838

3939
1. In your `composer.json` file, replace `"andrey-helldar/laravel-actions": "^1.0"` with `"dragon-code/laravel-migration-actions": "^2.0"`.
4040
2. Replace the `Helldar\LaravelActions` namespace prefix with `DragonCode\LaravelActions` in your app;
@@ -63,9 +63,9 @@ the `Register Service Providers` section of your `bootstrap/app.php`.
6363
$app->register(\DragonCode\LaravelActions\ServiceProvider::class);
6464
```
6565

66-
## How to use
66+
## How To Use
6767

68-
### Generating actions
68+
### Creating Actions
6969

7070
To create a migration, use the `make:migration:action` Artisan command:
7171

@@ -274,7 +274,7 @@ The `migrate:actions:status` command displays the execution status of actions. I
274274
php artisan migrate:actions:status
275275
```
276276

277-
### Execution status
277+
### Execution Status
278278

279279
You can also override the `success` and `failed` methods, which are called on success or failure processing.
280280

@@ -347,7 +347,29 @@ Call the `php artisan migrate:actions` command.
347347

348348
The log file will contain two `failed` entries.
349349

350+
### Artisan Command
350351

352+
Quite often, when working with actions, it becomes necessary to run one or another console command, and each time you have to write the following code:
353+
354+
```php
355+
use Illuminate\Support\Facades\Artisan;
356+
357+
public function up()
358+
{
359+
Artisan::call('command-name');
360+
}
361+
```
362+
363+
Since version [`2.3`](https://github.com/TheDragonCode/laravel-migration-actions/releases/tag/v2.3.0) we have added a method call. Now calling commands has become much easier:
364+
365+
```php
366+
public function up()
367+
{
368+
$this->artisan('command-name', [
369+
// parameters
370+
]);
371+
}
372+
```
351373

352374
## License
353375

src/Concerns/Artisan.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelActions\Concerns;
6+
7+
use Illuminate\Support\Facades\Artisan as ArtisanSupport;
8+
9+
trait Artisan
10+
{
11+
/**
12+
* Run an Artisan console command by name.
13+
*
14+
* @param string $command
15+
* @param array $parameters
16+
*
17+
* @return void
18+
*/
19+
protected function artisan(string $command, array $parameters = []): void
20+
{
21+
ArtisanSupport::call($command, $parameters);
22+
}
23+
}

src/Support/Actionable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace DragonCode\LaravelActions\Support;
44

55
use DragonCode\Contracts\LaravelActions\Actionable as Contract;
6+
use DragonCode\LaravelActions\Concerns\Artisan;
67
use Illuminate\Database\Migrations\Migration;
78
use Illuminate\Support\Arr;
89

910
abstract class Actionable extends Migration implements Contract
1011
{
12+
use Artisan;
13+
1114
/**
1215
* Determines the type of launch of the action.
1316
*

0 commit comments

Comments
 (0)