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
By default optimistic locking is enabled when you use
63
+
`OptimisticLocking` trait in your model, to alter the default
64
+
behaviour you can set the lock strictly to `false`:
65
+
66
+
```php
67
+
<?php
68
+
class BlogPost extends \Illuminate\Database\Eloquent\Model
69
+
{
70
+
use \Reshadman\OptimisticLocking\OptimisticLocking;
71
+
72
+
protected $lock = false;
73
+
}
74
+
```
75
+
and then you may enable it: `$blogPost->enableLocking();`
76
+
77
+
### Use a different column for tracking version
78
+
By default the `lock_version` column is used for tracking
79
+
version, you can alter that by overriding the following method
80
+
of the trait:
81
+
82
+
```php
83
+
<?php
84
+
class BlogPost extends \Illuminate\Database\Eloquent\Model
85
+
{
86
+
use \Reshadman\OptimisticLocking\OptimisticLocking;
87
+
88
+
/**
89
+
* Name of the lock version column.
90
+
*
91
+
* @return string
92
+
*/
93
+
protected static function lockVersionColumn()
94
+
{
95
+
return 'track_version';
96
+
}
97
+
}
98
+
```
52
99
53
100
## What is optimistic locking?
54
101
For detailed explanation read the concurrency section of [*Patterns of Enterprise Application Architecture by Martin Fowler*](https://www.martinfowler.com/eaaCatalog/optimisticOfflineLock.html).
@@ -74,14 +121,17 @@ business logic. That is simply via adding the following criteria
74
121
to the update query of a **optimistically lockable model**:
0 commit comments