Download the PHP package kenepa/resource-lock without Composer
On this page you can find all versions of the php package kenepa/resource-lock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kenepa/resource-lock
More information about kenepa/resource-lock
Files in kenepa/resource-lock
Package resource-lock
Short Description Filament Resource Lock is a Filament plugin that adds resource locking functionality to your site.
License MIT
Homepage https://github.com/kenepa/resource-lock
Informations about the package resource-lock
Resoure Lock
Filament Resource Lock is a Filament plugin that adds resource locking functionality to your site. When a user begins editing a resource, Filament Resource Lock automatically locks the resource to prevent other users from editing it at the same time. The resource will be automatically unlocked after a set period of time, or when the user saves or discards their changes.
Installation
Plugin Version | Filament Version | PHP Version |
---|---|---|
1.x | 2.x | > 8.0 |
2.x | 3.x | > 8.1 |
Notice - Upgrading to Version 2.1.x :
In case you have published the config, make sure to update the following in your config:
You can install the package via composer:
Then run the installation command to publish and run migration(s)
Register plugin with a panel
You can publish run the config (optional)
Usage
The Filament Resource Lock package enables you to lock a resource and prevent other users from editing it at the same time. Currently, this package only locks the EditRecord page and the edit modal when editing a simple modal resource. Follow the steps below to add locks to your resources.
Add Locks to your model
The first step is to add the HasLocks trait to the model of your resource. The HasLocks trait enables the locking functionality on your model.
Add Locks to your EditRecord Page
The second step is to add the UsesResourceLock trait to your EditRecord page. The UsesResourceLock trait enables the locking function on your edit page.
Simple modal Resource
If your resource is a simple modal resource, you'll need to use the UsesSimpleResourceLock trait instead.
And that's it! Your resource is now able to be locked. Refer to the documentation below for more information on how to configure the locking functionality.
Resource Lock manager
The package also provides a simple way to manage and view all your active and expired locks within your app. And it also provides a way to quickly unlock all resources or specific locks.
Configuration
Access
You can restrict the access to the Unlock button or to the resource manager by adjusting the access variable. Enabling the "limited" key and setting it to true allows you to specify either a Laravel Gate class or a permission name from the Spatie Permissions package.
Example
Using custom models
Sometimes, you may have a customized implementation for the User model in your application, or you may want to use a custom class for the ResourceLock functionality. In such cases, you can update the configuration file to specify the new class you want to use. This will ensure that the ResourceLock functionality works as expected with the new implementation.
Displaying the user who has locked the resource
Use the within the config to control whether or not the locked resource owner is displayed in the modal. Set the option to true to show the owner's username or other identifying information. The modal can be triggered by a button click or automatically when the resource is accessed.
By default, the package displays the name of the user: . However, if your user model doesn't have a name or you want to display a different identifier, you can create a custom action to overwrite the default behavior.
This package uses actions which allows you to implement your own custom logic. An action class is nothing more than a simple class with a method that executes some logic. Learn more about actions
To create a custom action, first create a file within your project and name it , for example. In this file, create a new class that extends the class and override the execute method to return the desired identifier. For example:
Next, register your custom action within the resource-lock.config file. Replace the default get_resource_lock_owner_action value with your custom action's class name. For example:
Overriding default functionality
If you need some custom functionality beyond what the traits provide, you can override the functions that they use. For example, if you want to change the URL that the "Return" button redirects to, you can override the resourceLockReturnUrl() function. By default, this button takes you to the index page of the resource, but you can change it to whatever URL you want by adding your custom implementation in the resourceLockReturnUrl() function.
For instance, if you want the "Return" button to redirect to https://laracasts.com, you can override the function as follows:
Now the return url will redirect to laracasts.com
This will change the behavior of the "Return" button to redirect to the provided URL.
Publishing migrations, configuration and view
You can publish and run the migrations with:
You can publish the config file with:
Optionally, you can publish the views using
Note: Publishing Blade views can introduce breaking changes into your app. If you're interested in how to stay safe, see this article by Dan Harrin.
T
Coming soon
- Locked status indicator for table rows
- Polling
- Optimistic Locking
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
All versions of resource-lock with dependencies
filament/filament Version ^3.0
spatie/laravel-package-tools Version ^1.15.0
illuminate/contracts Version ^9.0|^10.0|^11.0