{"id":18397419,"url":"https://github.com/lowerrocklabs/laravel-lockable","last_synced_at":"2025-04-07T04:33:17.394Z","repository":{"id":60653790,"uuid":"544401252","full_name":"LowerRockLabs/laravel-lockable","owner":"LowerRockLabs","description":"This simple package allows for Models to be locked for Editing (or Accessing) for a period of time.","archived":false,"fork":false,"pushed_at":"2025-02-03T19:35:47.000Z","size":526,"stargazers_count":8,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T13:37:36.133Z","etag":null,"topics":["laravel","laravel-package","lock","locking","model"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LowerRockLabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-02T11:39:04.000Z","updated_at":"2025-02-26T08:05:16.000Z","dependencies_parsed_at":"2024-07-09T00:07:24.909Z","dependency_job_id":"eb294821-672e-4073-905a-1d84f3b6eddd","html_url":"https://github.com/LowerRockLabs/laravel-lockable","commit_stats":{"total_commits":122,"total_committers":3,"mean_commits":"40.666666666666664","dds":"0.29508196721311475","last_synced_commit":"55529c6c503c958e74467723b84248791b38eb7c"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerRockLabs%2Flaravel-lockable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerRockLabs%2Flaravel-lockable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerRockLabs%2Flaravel-lockable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerRockLabs%2Flaravel-lockable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LowerRockLabs","download_url":"https://codeload.github.com/LowerRockLabs/laravel-lockable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595370,"owners_count":20963939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-package","lock","locking","model"],"created_at":"2024-11-06T02:17:01.025Z","updated_at":"2025-04-07T04:33:12.377Z","avatar_url":"https://github.com/LowerRockLabs.png","language":"PHP","readme":"# Laravel Lockable provides traits to allow for models to be locked\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/lowerrocklabs/laravel-lockable.svg?style=flat-square)](https://packagist.org/packages/lowerrocklabs/laravel-lockable)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/lowerrocklabs/laravel-lockable/run-tests?label=tests)](https://github.com/lowerrocklabs/laravel-lockable/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/lowerrocklabs/laravel-lockable/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/lowerrocklabs/laravel-lockable/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n\u003ca href=\"https://codeclimate.com/github/LowerRockLabs/laravel-lockable/maintainability\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/de42e3f05d0cb1629c8d/maintainability\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://codeclimate.com/github/LowerRockLabs/laravel-lockable/test_coverage\"\u003e\u003cimg src=\"https://api.codeclimate.com/v1/badges/de42e3f05d0cb1629c8d/test_coverage\" /\u003e\u003c/a\u003e\n[![Total Downloads](https://img.shields.io/packagist/dt/lowerrocklabs/laravel-lockable.svg?style=flat-square)](https://packagist.org/packages/lowerrocklabs/laravel-lockable)\n\nThis model allows for on-demand locking of models.  You can integrate this with your permissions methodology of choice, or leave it stand-alone.  This package allows you to determine whether a particular instance of a model is Locked or Not.  Or it will independently prevent updating of a model instance.\n\n## Installation\n\u003e **Requires [PHP 7.3+ or 8.0+] and [Laravel 8.x or 9.x] (https://laravel.com/docs/8.x/releases or https://laravel.com/docs/9.x/releases)**\n\nYou can install the package via composer:\n\n```bash\ncomposer require lowerrocklabs/laravel-lockable\n```\n\nYou can publish and run the migrations with:\n\n```bash\nphp artisan vendor:publish --tag=\"laravel-lockable-migrations\"\nphp artisan migrate\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"laravel-lockable-config\"\n```\n\nThis is the contents of the published config file, which controls the global lock duration, this is customisable on a per-model basis (see below).\n\n```php\nreturn [\n    // Name of the Table containing the locks\n    'locks_table' =\u003e 'model_locks',\n    \n     // Name of the Table containing the lock watchers\n    'lock_watchers_table' =\u003e 'model_lock_watchers',\n    \n    // Enable retrieval of lock status on retrieving a model\n    'get_locked_on_retrieve' =\u003e true,\n    \n    // Prevent updating if a model is locked by another user\n    'prevent_updating' =\u003e true,\n\n    // Time in Seconds For Lock To Persist\n    'duration' =\u003e '3600',\n];\n```\n\n\n## Usage\n\n#### Model Configuration\nIn the Model(s) that you wish to be lockable, add the IsLockable Trait\n\n```php\nuse LowerRockLabs\\Lockable\\Traits\\IsLockable;\n```\n\nand then set the Trait\n\n```php\nuse IsLockable;\n```\n\n#### In Your Component/Controller\nThen use the acquireLock function to attempt to acquire a lock on the model, it will return false if there is an existing lock.\n```php\nacquireLock()\n```\n\nYou can override the existing lock by calling the releaseLock() function before acquireLock(), if you are using a permissions-based approach, it is suggested that you restrict this to approriate users.\n```php\nreleaseLock()\n```\n\nYou can tell if a lock exists as follows, this will acquire the lock if one does not exist.\n```php\nisLocked()\n```\n\nYou can send a Broadcast to the user holding the lock with the following\n```php\nrequestLock()\n```\n\n#### Lock Duration\nYou can override the default Lock Duration (in seconds) which is taken from the configuration on a per-model basis by setting the following in your Model, for example, the following would limit the duration of a lock to 600 seconds.\n\n```php\npublic $modelLockDuration = \"600\";\n```\n\nLocks will clear when the Duration has expired, and an attempt is made to access the Model, or you can call the commands below, or add them to a schedule (as you see fit).\n\n#### Commands\n\n**To Flush Expired Locks**\n```php \nphp artisan locks:flushexpired\n```\n\n**To Flush All Locks**\n```php \nphp artisan locks:flushall\n```\n\n\n#### Events\nTwo Events will be fired during the Lock process, that can be used to fire Notifications or Logs if desired\n**On Model Locking**\n```php\nLowerRockLabs\\Lockable\\Events\\ModelWasLocked;\n```\nand\n**On Model UnLocking**\n```php\nLowerRockLabs\\Lockable\\Events\\ModelWasUnLocked;\n```\n\nAn additional event will be fired when a user requests the release of the lock\nand\n**On Model UnLocking**\n```php\nLowerRockLabs\\Lockable\\Events\\ModelUnlockRequested;\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Joe](https://github.com/LowerRockLabs)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flowerrocklabs%2Flaravel-lockable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flowerrocklabs%2Flaravel-lockable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flowerrocklabs%2Flaravel-lockable/lists"}