-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5643da1
commit 92f0f50
Showing
1 changed file
with
30 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|