PHP code example of angle / keyable

1. Go to this page and download the library: Download angle/keyable 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/ */

    

angle / keyable example snippets




namespace App;

use Angle\Keyable\Keyable;
use Illuminate\Database\Eloquent\Model;

class Vault extends Model
{
    use Keyable;

    /**
     * Attributes containing unique keys.
     *
     * @var array
     */
    public $keys = ['fingerprint' => 256];
}



namespace App;

use Angle\Keyable\Keyable;
use Illuminate\Database\Eloquent\Model;

class Endpoint extends Model
{
    use Keyable;

    /**
     * Attributes containing unique keys.
     *
     * @var array
     */
    public $keys = [
        'public_key' => 128,
        'private_key' => 128
    ];

    public function keyableStrategy(string $attribute, int $length) : string
    {
        $prefix = 'public-';

        if ($attribute == 'private_key') {
            $prefix = 'private-';
        }

        return $prefix . \Str::random($length);
    }
}