You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-10Lines changed: 36 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,8 @@
26
26
*[Generating actions](#generating-actions)
27
27
*[Running Actions](#running-actions)
28
28
*[Forcing Actions To Run In Production](#forcing-actions-to-run-in-production)
29
-
*[Execution every time](#execution-every-time)
29
+
*[Execution Every Time](#execution-every-time)
30
+
*[Database Transactions](#database-transactions)
30
31
*[Rolling Back Actions](#rolling-back-actions)
31
32
*[Roll Back & Action Using A Single Command](#roll-back--action-using-a-single-command)
32
33
*[Actions Status](#actions-status)
@@ -110,7 +111,7 @@ database, you will be prompted for confirmation before the commands are executed
110
111
php artisan migrate:actions --force
111
112
```
112
113
113
-
#### Execution every time
114
+
#### Execution Every Time
114
115
115
116
In some cases, you need to call the code every time you deploy the application. For example, to call reindexing.
116
117
@@ -121,14 +122,6 @@ use Helldar\LaravelActions\Support\Actionable;
121
122
122
123
class Reindex extends Actionable
123
124
{
124
-
/**
125
-
* Determines the type of launch of the action.
126
-
*
127
-
* If true, then it will be executed once.
128
-
* If false, then the action will run every time the `migrate:actions` command is invoked.
129
-
*
130
-
* @var bool
131
-
*/
132
125
protected $once = false;
133
126
134
127
public function up(): void
@@ -148,6 +141,39 @@ If the value is `$once = false`, the `up` method will be called every time the `
148
141
In this case, information about it will not be written to the `migration_actions` table and, therefore, the `down` method will not be called when the rollback
149
142
command is called.
150
143
144
+
#### Database Transactions
145
+
146
+
In some cases, it becomes necessary to undo previously performed actions in the database. For example, when code execution throws an error. To do this, the code
147
+
must be wrapped in a transaction.
148
+
149
+
By setting the `$transactions = true` parameter, you will ensure that your code is wrapped in a transaction without having to manually call
150
+
the `DB::transaction()` method. This will reduce the time it takes to create the action.
151
+
152
+
```php
153
+
use Helldar\LaravelActions\Support\Actionable;
154
+
155
+
class AddSomeData extends Actionable
156
+
{
157
+
protected $transactions = true;
158
+
159
+
public function up(): void
160
+
{
161
+
// ...
162
+
163
+
$post = Post::create([
164
+
'title' => 'Random Title'
165
+
]);
166
+
167
+
$post->tags()->sync($ids);
168
+
}
169
+
170
+
public function down(): void
171
+
{
172
+
//
173
+
}
174
+
}
175
+
```
176
+
151
177
### Rolling Back Actions
152
178
153
179
To roll back the latest action operation, you may use the `rollback` command. This command rolls back the last "batch" of actions, which may include multiple
0 commit comments