https://github.com/nckg/laravel-impersonate
Easily impersonate any user in a Laravel Application
https://github.com/nckg/laravel-impersonate
impersonate laravel laravel-application middleware php
Last synced: 20 days ago
JSON representation
Easily impersonate any user in a Laravel Application
- Host: GitHub
- URL: https://github.com/nckg/laravel-impersonate
- Owner: nckg
- License: mit
- Created: 2016-10-28T10:59:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-21T11:32:39.000Z (over 4 years ago)
- Last Synced: 2025-08-29T12:11:07.510Z (about 1 month ago)
- Topics: impersonate, laravel, laravel-application, middleware, php
- Language: PHP
- Size: 7.81 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Impersonate
[](https://travis-ci.org/nckg/laravel-impersonate) [](https://github.com/nckg/laravel-impersonate) [](https://github.com/nckg/laravel-impersonate)## Introduction
Easily impersonate any user in your Laravel Application
## Installation
You can install the package via composer:
``` bash
composer require nckg/laravel-impersonate
```Add following code to your user model:
```php
class User
{
use \Nckg\Impersonate\Traits\CanImpersonate;
}
```Add following code to your routes file:
```php
Route::get('users/{id}/impersonate', function ($id) {
\Auth::user()->setImpersonating($id);
return redirect()->back();
});
Route::get('users/stop-impersonate', function () {
\Auth::user()->stopImpersonating();
return redirect()->back();
});
```If you are using Laravel you can add the middleware to your middleware providers
```php
// app/Http/Kernel.php
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
...
\Nckg\Impersonate\Impersonate::class,
];
```## Testing
``` bash
composer test
```## License
The MIT License (MIT).