Model (Trait) Methods

The LockableRecord trait provides the following methods and attributes (getters):

$model->lockRecord() attempts to lock the record for editing - returns true/false to indicate whether it was successful.

$model->unlockRecord() releases the current users lock - returns true if it was unlocked (or not previously locked); false if someone else holds the lock.

$model->stealLock() replaces the existing lock with a lock for the current user.

$model->can_lock returns true if the record can be locked (i.e. is not currently locked by another user); false otherwise.

$model->locked_by_id returns ID of the user that currently has a lock on the record; null if no-one has a lock.

$model->lockedBy returns the User model of the user that currently has a lock on the record; null if no-one has a lock. $model->lockedBy() is the corresponding BelongsTo relationship.

$model->lock_key is used internally to determine the key used for locking the record - defaults to {table}.{id}, but it can be overridden.

For more advanced use cases, you can use the Alberon\NexusRecordLocking\Support\RecordLockManager class methods directly.