PHP code example of alp-develop / laravel-impersonate

1. Go to this page and download the library: Download alp-develop/laravel-impersonate 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/ */

    

alp-develop / laravel-impersonate example snippets


use AlpDevelop\LaravelImpersonate\Contracts\Impersonatable;
use AlpDevelop\LaravelImpersonate\Traits\HasImpersonation;

class User extends Authenticatable implements Impersonatable
{
    use HasImpersonation;
}

use Illuminate\Support\Facades\Gate;

Gate::define('impersonate', function ($user, $target) {
    return $user->is_admin;
});

use AlpDevelop\LaravelImpersonate\Facades\Impersonate;

Impersonate::start($targetUser);
Impersonate::start($targetUser, ttl: 30);
Impersonate::stop();
bash
php artisan vendor:publish --tag=impersonate-config