andach / laravel-signoff
This is a package to allow for Laravel models to be 'signed off' as approved.
Requires
- php: ^8.1
- andach/laravel-primary-key-uuid: ^1.0
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-10-18 16:24:29 UTC
README
This is a Laravel package to add the ability to sign off another model, to have a second signoff, and includes a Javascript signature pad option
It integrates with https://github.com/szimek/signature_pad to provide a simple image if you provide a pad called "sign".
Installation
You can install the package via composer:
composer require andach/laravel-signoff
You can publish the migrations with:
php artisan signoff:install
And if desired, can publish the views with:
php artisan vendor:publish --tag=signoff-views
Signature Pad
This package integrates with https://github.com/szimek/signature_pad. To use, you should enable the relevant option in the config file and include the Javascript.
npm install --save signature_pad
And then include the javascript in ./js/app.js into your ./resources/js/app.js file.
Usage
To use, simply add the MorphToSignoff
trait and Signoffable
interface to the model you want to be able to sign off.
use Andach\LaravelSignoff\Interfaces\Signoffable;
use Andach\Signoff\Traits\MorphToSignoff;
class MyModel extends Model implements Signoffable
{
use MorphToSignoff;
// ...
}
Then you can call functions as needed:
$model = new MyModel();
// Create a signoff requirement.
$model->signoff()->create([
// The user_id is optional, and specifies who needs to sign off the model. If null, anyone can sign it off.
'user_id' => 123,
// A boolean flag. Note that if not required, the item can still be signed off by another user.
'is_second_signoff_required' => true,
//Similarly, limits who can provide the second signoff.
'second_user_id' => 456,
]);
// Check if the model has been signed off.
$model->isFirstSignedOff(); // false
$model->isFullySignedOff(); // false
// Sign off the model.
$model->doFirstSignoff();
// And now...
$model->isFirstSignedOff(); // true
$model->isFullySignedOff(); // false
// Provide second signoff
$model->doSecondSignoff();
// Finally...
$model->isFirstSignedOff(); // true
$model->isFullySignedOff(); // true
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.