Description
Laravel pad signature. A Laravel package to sign documents and optionally generate certified PDFs associated to a Eloquent model.
Add the RequiresSignature trait and implement the CanBeSigned class to the model you would like.
<?php namespace App\Models; use Creagia\LaravelSignPad\Concerns\RequiresSignature;use Creagia\LaravelSignPad\Contracts\CanBeSigned; class MyModel extends Model implements CanBeSigned{ use RequiresSignature; } ?>
If you want to generate PDF documents with the signature, you should implement the ShouldGenerateSignatureDocument class . Define your document template with the getSignatureDocumentTemplate method.
<?php namespace App\Models; use Creagia\LaravelSignPad\Concerns\RequiresSignature;use Creagia\LaravelSignPad\Contracts\CanBeSigned;use Creagia\LaravelSignPad\Contracts\ShouldGenerateSignatureDocument;use Creagia\LaravelSignPad\Templates\BladeDocumentTemplate;use Creagia\LaravelSignPad\Templates\PdfDocumentTemplate;use Creagia\LaravelSignPad\SignatureDocumentTemplate;use Creagia\LaravelSignPad\SignaturePosition; class MyModel extends Model implements CanBeSigned, ShouldGenerateSignatureDocument{ use RequiresSignature; public function getSignatureDocumentTemplate(): SignatureDocumentTemplate { return new SignatureDocumentTemplate( outputPdfPrefix: 'document', // optional // template: new BladeDocumentTemplate('pdf/my-pdf-blade-template'), // Uncomment for Blade template // template: new PdfDocumentTemplate(storage_path('pdf/template.pdf')), // Uncomment for PDF template signaturePositions: [ new SignaturePosition( signaturePage: 1, signatureX: 20, signatureY: 25, ), new SignaturePosition( signaturePage: 2, signatureX: 25, signatureY: 50, ), ] ); }} ?>
A $model object will be automatically injected into the Blade template, so you will be able to access all the needed properties of the model.
Usage
At this point, all you need is to create the form with the sign pad canvas in your template. For the route of the form, you have to call the method getSignatureRoute() from the instance of the model you prepared before:
@if (!$myModel->hasBeenSigned()) <form action="{{ $myModel->getSignatureRoute() }}" method="POST"> @csrf <div style="text-align: center"> <x-creagia-signature-pad /> </div> </form> <script src="{{ asset('vendor/sign-pad/sign-pad.min.js') }}"></script>@endif
Retrieving signatures
You can retrieve your model signature using the Eloquent relation $myModel->signature. After that,
you can use:
getSignatureImagePath()returns the signature image path.getSignatureImageAbsolutePath()returns the signature image absolute path.getSignedDocumentPath()returns the generated PDF document path.getSignedDocumentAbsolutePath()returns the generated PDF document absolute path.
echo $myModel->signature->getSignatureImagePath();echo $myModel->signature->getSignedDocumentPath();
Deleting signatures
You can delete your model signature using
deleteSignature()method in the model.
echo $myModel->deleteSignature();