Package Data | |
---|---|
Maintainer Username: | stenin-nikita |
Maintainer Contact: | stenin.nikita@gmail.com (Nikita Stenin) |
Package Create Date: | 2017-01-25 |
Package Last Update: | 2017-01-27 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-22 03:02:43 |
Package Statistics | |
---|---|
Total Downloads: | 980 |
Monthly Downloads: | 15 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Impersonating user for Laravel application.
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('/');
});
You can run the tests with:
vendor/bin/phpunit
The MIT License (MIT). Please see License File for more information.