PHP code example of arjanwestdorp / exposable

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

    

arjanwestdorp / exposable example snippets


// config/app.php
'providers' => [
    ...
    ArjanWestdorp\Exposable\ExposableServiceProvider::class,
];

namespace App;
    
use ArjanWestdorp\Exposable\Exposable;
use Illuminate\Database\Eloquent\Model;
    
class File extends Model {
    
    use Exposable;

}

namespace App;
    
use ArjanWestdorp\Exposable\Exposable;
use Illuminate\Database\Eloquent\Model;
    
class File extends Model {
    
    use Exposable;
    
    /**
     * Expose the model.
     *
     * @return \Illuminate\Http\Response
     */
    public function expose()
    {
        return response('My secure content');
    }
}

'exposables' => [
    'file' => App\File::class,
],

$file = File::first();
echo $file->exposeUrl();
    
// http://app.app/expose/file/1?expire=1483261800&guard=member&signature=716817ecaed63fa8b1b887b64ab9505d90cf065dc0677d8b011e3a8b014c43e0

namespace App;
    
use ArjanWestdorp\Exposable\Exposable;
use Illuminate\Database\Eloquent\Model;
    
class File extends Model {
    
    use Exposable;
    
    /**
     * The time the expose url will be valid.
     *
     * @var string
     */
    protected $exposableLifetime = '2 hours';
    
    /**
     * The guard to use when exposing this model.
     *
     * @var string
     */
    protected $exposableGuard = 'member';
    
    /**
     * Expose the model.
     *
     * @return \Illuminate\Http\Response
     */
    public function expose()
    {
        return response('My secure content');
    }
}

namespace App\Guards;
    
use ArjanWestdorp\Exposable\Guards\Guard;
 
class MemberGuard implements Guard{
    
    /**
     * Check if the user is authenticated and if he is a member.
     * 
     * @return bool
     */
    public function authenticate(){
        if(!auth()->check()){
            return false;
        }
        
        return auth()->user()->isMember();
    }
}

'guards' => [
    ...
    'member' => \App\Guards\MemberGuard::class,
],
bash
php artisan vendor:publish --provider="ArjanWestdorp\Exposable\ExposableServiceProvider" --tag="config"