Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Dec 7, 2023
1 parent 5643da1 commit 92f0f50
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,41 +1049,45 @@ try {
A shorthand method to achieve the same thing would be to use the `transaction` method with a callable:

```php
Record::transaction(function(){
$user = new Users([
'username' => 'testuser',
'password' => 'password',
'email' => '[email protected]'
]);
$user->save();

$role = new Roles([
'role' => 'Admin'
]);
$role->save();
});
try {
Record::transaction(function() {
$user = new Users([
'username' => 'testuser',
'password' => 'password',
'email' => '[email protected]'
]);
$user->save();

$role = new Roles([
'role' => 'Admin'
]);
$role->save();
});
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
```


Nested transactions are supported as well:

```php
try {
Record::transaction(function(){
$user = new Users([
'username' => 'testuser',
'password' => 'password',
'email' => '[email protected]'
]);
$user->save();

Record::transaction(function(){
$role = new Roles([
'role' => 'Admin'
Record::transaction(function() {
$user = new Users([
'username' => 'testuser',
'password' => 'password',
'email' => '[email protected]'
]);
$role->save();
$user->save();

Record::transaction(function(){
$role = new Roles([
'role' => 'Admin'
]);
$role->save();
});
});
});
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Expand Down

0 comments on commit 92f0f50

Please sign in to comment.