Skip to content

Commit

Permalink
More details in README
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed Jun 21, 2022
1 parent dd9c48a commit c00dd70
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ In your migration classes, add the version column to your table as below:
public function up()
{
Schema::table('blog_posts', function (Blueprint $table) {
// create column for version tracking i.e., lock_version
$table->lockVersion();
// or to use a custom column name e.g., version
$table->lockVersion('version');
});
}

Expand All @@ -38,7 +41,7 @@ public function up()
public function down()
{
Schema::table('blog_posts', function (Blueprint $table) {
$table->dropLockVersion();
$table->dropLockVersion(); // or $table->dropLockVersion('version');
});
}
```
Expand All @@ -54,6 +57,14 @@ use Quarks\Laravel\Locking\LocksVersion;
class BlogPost extends Authenticatable
{
use LocksVersion;

/**
* Override the default lock version column name, optional.
*/
protected static function lockVersionColumnName()
{
return 'lock_version'; // or return 'version'; etc.
}
}
```

Expand Down Expand Up @@ -86,6 +97,7 @@ class BlogPostController extends Controller
$data = $request->validated();
$blogPost->fill($data);
$blogPost->fillLockVersion();

try {
$blogPost->save();
} catch (LockedVersionMismatchException $e) {
Expand Down

0 comments on commit c00dd70

Please sign in to comment.