Skip to content

Commit 4fc8f1d

Browse files
author
Andrey Helldar
authored
Merge pull request #35 from TheDragonCode/2.x
Update README.md
2 parents 9e6313f + 095a652 commit 4fc8f1d

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Laravel Migration Actions
22

3-
<img src="https://preview.dragon-code.pro/TheDragonCode/migration-actions.svg?brand=laravel" alt="Laravel Migration Actions"/>
3+
![the dragon code migration actions](https://preview.dragon-code.pro/the-dragon-code/migration-actions.svg?brand=laravel)
44

55
[![Stable Version][badge_stable]][link_packagist]
66
[![Unstable Version][badge_unstable]][link_packagist]
@@ -23,7 +23,7 @@ Or manually update `require` block of `composer.json` and run `composer update`.
2323
```json
2424
{
2525
"require": {
26-
"dragon-code/laravel-migration-actions": "^2.3"
26+
"dragon-code/laravel-migration-actions": "^2.4"
2727
}
2828
}
2929
```
@@ -105,15 +105,15 @@ To do this, override the `$once` variable in the action file:
105105
```php
106106
use DragonCode\LaravelActions\Support\Actionable;
107107

108-
class Reindex extends Actionable
108+
return new class extends Actionable
109109
{
110110
protected $once = false;
111111

112112
public function up(): void
113113
{
114114
// your code
115115
}
116-
}
116+
};
117117
```
118118

119119
If the value is `$once = false`, the `up` method will be called every time the `migrate:actions` command called.
@@ -129,7 +129,7 @@ For this you can use the `$environment` parameter:
129129
```php
130130
use DragonCode\LaravelActions\Support\Actionable;
131131

132-
class Reindex extends Actionable
132+
return new class extends Actionable
133133
{
134134
/** @var string|array|null */
135135
protected $environment = 'production';
@@ -138,15 +138,15 @@ class Reindex extends Actionable
138138
{
139139
// your code
140140
}
141-
}
141+
};
142142
```
143143

144144
You can also specify multiple environment names:
145145

146146
```php
147147
use DragonCode\LaravelActions\Support\Actionable;
148148

149-
class Reindex extends Actionable
149+
return new class extends Actionable
150150
{
151151
/** @var string|array|null */
152152
protected $environment = ['testing', 'staging'];
@@ -155,7 +155,7 @@ class Reindex extends Actionable
155155
{
156156
// your code
157157
}
158-
}
158+
};
159159
```
160160

161161
By default, the action will run in all environments. The same will happen if you specify `null` or `[]` as the value.
@@ -169,7 +169,7 @@ For this you can use the `$except_environment` parameter:
169169
```php
170170
use DragonCode\LaravelActions\Support\Actionable;
171171

172-
class Reindex extends Actionable
172+
return new class extends Actionable
173173
{
174174
/** @var string|array|null */
175175
protected $except_environment = 'production';
@@ -178,15 +178,15 @@ class Reindex extends Actionable
178178
{
179179
// your code
180180
}
181-
}
181+
};
182182
```
183183

184184
You can also specify multiple environment names:
185185

186186
```php
187187
use DragonCode\LaravelActions\Support\Actionable;
188188

189-
class Reindex extends Actionable
189+
return new class extends Actionable
190190
{
191191
/** @var string|array|null */
192192
protected $except_environment = ['testing', 'staging'];
@@ -195,7 +195,7 @@ class Reindex extends Actionable
195195
{
196196
// your code
197197
}
198-
}
198+
};
199199
```
200200

201201
By default, no actions will be excluded. The same happens if you specify `null` or `[]` value.
@@ -211,7 +211,7 @@ will reduce the time it takes to create the action.
211211
```php
212212
use DragonCode\LaravelActions\Support\Actionable;
213213

214-
class AddSomeData extends Actionable
214+
return new class extends Actionable
215215
{
216216
protected $transactions = true;
217217

@@ -227,7 +227,7 @@ class AddSomeData extends Actionable
227227

228228
$post->tags()->sync($ids);
229229
}
230-
}
230+
};
231231
```
232232

233233
### Rolling Back Actions
@@ -284,7 +284,7 @@ You can also override the `success` and `failed` methods, which are called on su
284284
use DragonCode\LaravelActions\Support\Actionable;
285285
use Illuminate\Support\Facade\Log;
286286

287-
class AddSomeData extends Actionable
287+
return new class extends Actionable
288288
{
289289
public function up(): void
290290
{
@@ -305,7 +305,7 @@ class AddSomeData extends Actionable
305305
{
306306
Log::info('failed');
307307
}
308-
}
308+
};
309309
```
310310

311311
Call the `php artisan migrate:actions` command.
@@ -319,7 +319,7 @@ use DragonCode\LaravelActions\Support\Actionable;
319319
use Exeption;
320320
use Illuminate\Support\Facade\Log;
321321

322-
class AddSomeData extends Actionable
322+
return new class extends Actionable
323323
{
324324
public function up(): void
325325
{
@@ -340,7 +340,7 @@ class AddSomeData extends Actionable
340340
{
341341
Log::info('failed');
342342
}
343-
}
343+
};
344344
```
345345

346346
Call the `php artisan migrate:actions` command.
@@ -352,25 +352,34 @@ The log file will contain two `failed` entries.
352352
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:
353353

354354
```php
355+
use DragonCode\LaravelActions\Support\Actionable;
355356
use Illuminate\Support\Facades\Artisan;
356357

357-
public function up()
358+
return new class extends Actionable
358359
{
359-
Artisan::call('command-name', [
360-
// parameters
361-
]);
362-
}
360+
public function up()
361+
{
362+
Artisan::call('command-name', [
363+
// parameters
364+
]);
365+
}
366+
};
363367
```
364368

365369
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:
366370

367371
```php
368-
public function up()
372+
use DragonCode\LaravelActions\Support\Actionable;
373+
374+
return new class extends Actionable
369375
{
370-
$this->artisan('command-name', [
371-
// parameters
372-
]);
373-
}
376+
public function up()
377+
{
378+
$this->artisan('command-name', [
379+
// parameters
380+
]);
381+
}
382+
};
374383
```
375384

376385
## License

0 commit comments

Comments
 (0)