PHP code example of conttas / laravel-signed-url

1. Go to this page and download the library: Download conttas/laravel-signed-url 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/ */

    

conttas / laravel-signed-url example snippets


SignedUrl::sign('https://myapp.com/protected-route', 30);

SignedUrl::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

// config/app.php

'providers' => [
    ...
    Akaunting\SignedUrl\Provider::class,
];

'aliases' => [
    ...
    'SignedUrl' => Akaunting\SignedUrl\Facade::class,
];

return [

    /*
    * This string is used the to generate a signature. You should
    * keep this value secret.
    */
    'signatureKey' => env('APP_KEY'),

    /*
     * The default expiration time of a URL in days.
     */
    'default_expiration_time_in_days' => 1,

    /*
     * These strings are used a parameter names in a signed url.
     */
    'parameters' => [
        'expires' => 'expires',
        'signature' => 'signature',
    ],

    /*
    |--------------------------------------------------------------------------
    | Middleware
    |--------------------------------------------------------------------------
    |
    | This option indicates the middleware to change language.
    |
    */
    'middleware'    => 'Akaunting\SignedUrl\Middleware\ValidateSignedUrl',

];

SignedUrl::sign('https://myapp.com/protected-route');

//the generated URL will be valid for 5 days.
SignedUrl::sign('https://myapp.com/protected-route', 5);

//This URL will be valid up until 2 hours from the moment it was generated.
SignedUrl::sign('https://myapp.com/protected-route', Carbon\Carbon::now()->addHours(2) );

SignedUrl::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

Route::get('protected-route', ['middleware' => 'signed', function () {
    return 'Hello secret world!';
}]);

php artisan vendor:publish --provider=signed-url