1. Go to this page and download the library: Download hotrush/laravel-signer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hotrush / laravel-signer example snippets
use Hotrush\Signer\Contracts\Signable;
class Post extends Model implements Signable
{
}
use Hotrush\Signer\Contracts\Signable;
use Hotrush\Signer\Contracts\Traits\CanBeSigned;
class Post extends Model implements Signable
{
use CanBeSigned;
/**
* Return null if never expires.
*
* @return Carbon|null
*/
public function getSignExpiration(): ?Carbon
{
return null;
}
/**
* Payload used for making signature hash.
*
* @return array
*/
public function getSignPayload(): array
{
return [
$this->getKeyName() => $this->getKey(),
'field' => $this->field,
];
}
/**
* Payload put into encoded code. Will be publicly accessible.
*
* @return array
*/
public function getPublicSignPayload(): array
{
return [
$this->getKeyName() => $this->getKey(),
];
}
/**
* Define where clause for getting signable model instance by signature.
* Only values from public payload can be used.
*/
public static function signableClauses(Signature $signature): \Closure
{
return function (Builder $query) use ($signature) {
$query->where('id', '=', $signature->payload['id']);
};
}
}