New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

laracomponents/impersonation

Impersonating user for Laravel application.
1,044 2
Install
composer require laracomponents/impersonation
Latest Version:v1.0.1
PHP:>=5.6.4
Laravel:5
License:MIT
Last Updated:Jan 27, 2017
Links: GitHub  ·  Packagist
Maintainer: stenin-nikita

Impersonation for Laravel

Build Status Latest Version Quality Score StyleCI Total Downloads Software License

Introduction

Impersonating user for Laravel application.

Installation

You can install this package via composer using this command:

composer require laracomponents/impersonation

Next, you must add the Impersonable trait to the user model:

use LaraComponents\Impersonation\Traits\Impersonable;

class User
{
    use Impersonable;
    ...

    /**
     * Optional method
     * Default return the "impersonate_id"
    **/
    public function getImpersonatingKey()
    {
        return 'your session key here';
    }
}

Open App/Http/Kernal.php and add middleware to web middleware group:

    protected $middlewareGroups = [
        'web' => [
            ...
            \LaraComponents\Impersonation\Middleware\CheckForImpersonating::class,
        ],
        ...
    ];

And finally you should add a routes to routes/web.php. Example:

Route::get('users/{id}/impersonate', function ($id) {
    $user = \App\User::findOrFail($id);

    if(! $user->isImpersonating()) {
        $user->impersonate();
    }

    return redirect('/');
});

Route::get('users/unimpersonate', function () {
    $user = \Auth::user();

    if($user->isImpersonating()) {
        $user->unimpersonate();
    }

    return redirect('/');
});

Testing

You can run the tests with:

vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

Related Packages

christhompsontldr/impersonate

Allows a user to impersonate another user.

484 0
franbarbalopez/mirror

Mirror is a Laravel package that handles user impersonation.

63,222 162
laravel-enso/impersonate

User impersonation support for Laravel Enso

61,976 8
bizhub/impersonate

Impersonate a Laravel user

5,581 2
scif/laravel-pretend

Symfony style impersonation for the Laravel Framework.

129 5

Version History

Version Released PHP Laravel License
v1.0.1 >=5.6.4 ~5.3.0|~5.4.0 MIT
v1.0.0 >=5.6.4 ~5.3.0|~5.4.0 MIT