{"id":34017217,"url":"https://github.com/octopyid/larapersonate","last_synced_at":"2025-12-13T14:29:02.094Z","repository":{"id":42615681,"uuid":"284544293","full_name":"OctopyID/LaraPersonate","owner":"OctopyID","description":"Login as a different user quickly for Laravel","archived":false,"fork":false,"pushed_at":"2025-03-18T18:00:12.000Z","size":10949,"stargazers_count":320,"open_issues_count":1,"forks_count":29,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-03T00:51:49.467Z","etag":null,"topics":["administration","eloquent","impersonate","laravel","laravel-package","php","sudo-su"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OctopyID.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"SupianIDz","ko_fi":"SupianIDz"}},"created_at":"2020-08-02T21:24:04.000Z","updated_at":"2025-12-02T14:26:25.000Z","dependencies_parsed_at":"2024-01-15T09:03:24.376Z","dependency_job_id":"dc81aee7-6eda-424d-9839-b27d8ecd1337","html_url":"https://github.com/OctopyID/LaraPersonate","commit_stats":{"total_commits":130,"total_committers":4,"mean_commits":32.5,"dds":"0.023076923076923106","last_synced_commit":"893a7e20e91fe83a74b57a8f53512212e7a73d7c"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/OctopyID/LaraPersonate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctopyID%2FLaraPersonate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctopyID%2FLaraPersonate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctopyID%2FLaraPersonate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctopyID%2FLaraPersonate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OctopyID","download_url":"https://codeload.github.com/OctopyID/LaraPersonate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OctopyID%2FLaraPersonate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27707048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["administration","eloquent","impersonate","laravel","laravel-package","php","sudo-su"],"created_at":"2025-12-13T14:29:00.870Z","updated_at":"2025-12-13T14:29:02.083Z","avatar_url":"https://github.com/OctopyID.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"demo.gif\" alt=\"Demo\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/OctopyID/LaraPersonate/tests.yml?branch=main\u0026style=for-the-badge\" alt=\"Tests\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/v/octopyid/laravel-impersonate.svg?style=for-the-badge\" alt=\"Version\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/dt/octopyid/laravel-impersonate.svg?style=for-the-badge\u0026color=F28D1A\" alt=\"Downloads\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/l/octopyid/laravel-impersonate.svg?style=for-the-badge\" alt=\"License\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Safouene1/support-palestine-banner/Markdown-pages/Support.md\"\u003e \n        \u003cimg src=\"https://raw.githubusercontent.com/Safouene1/support-palestine-banner/master/banner-support.svg\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# Laravel Impersonate\n\nIs an Impersonation package for the Laravel Framework. With this package you can easily impersonate other users either manually or using the interface we provide.\n\nYou don't have to worry about authorizing who can impersonate or who can be impersonated, coz we provided it by default, just need to adjust it a little according to your\nrules.\n\n| Impersonate                                                 | Laravel     | Impersonate                                                 | Laravel   |\n|-------------------------------------------------------------|-------------|-------------------------------------------------------------|-----------|\n| [v4.x](https://github.com/OctopyID/LaraPersonate/tree/main) | 10.x - 12.x | [v2.x](https://github.com/OctopyID/LaraPersonate/tree/v2.x) | 7.x - 8.x |\n| [v3.x](https://github.com/OctopyID/LaraPersonate/tree/v3.x) | 9.x - 10.x  | [v1.x](https://github.com/OctopyID/LaraPersonate/tree/v1.x) | 7.x - 8.x |\n\n## Installation\n\n\u003e **Warning**\n\u003e\n\u003e This version is a breaking change, many changes were made to the addition of new features, new UI design, and code structure.\n\u003e\n\u003e If you are upgrade from an old version, please delete the old assets and republish the assets, configure and reset the [limitations](#311-defining-limitation) on the User Model\n\u003e according to this version.\n\nTo install the package, simply follow the steps below.\n\n### Install The Package\n\n```bash\ncomposer require octopyid/laravel-impersonate:^4\n```\n\n### Publish The Package\n\n```bash\nphp artisan vendor:publish --tag=\"impersonate\"\n```\n\n\u003e **Note**\n\u003e\n\u003e Sometimes some users experience the problem of layout after upgrading the package, this can be solved by deleting the `public/vendor/octopyid/impersonate` folder then republish\n\u003e the assets.\n\n### Add `HasImpersonation` Trait to  User Model\n\nAdd the trait `Octopy\\Impersonate\\Concerns\\HasImpersonation` to your **User** model.\n\n```php\nnamespace App\\Models;\n\nuse Octopy\\Impersonate\\Concerns\\HasImpersonation;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;     \n\nclass User extends Authenticatable\n{\n    use HasImpersonation;\n}\n\n```\n\nIf you plan to use the provided UI, add `Octopy\\Impersonate\\Contracts\\HasImpersonationUI` interface to add mandatory configuration for the UI.\n\n```php\nnamespace App\\Models;\n\nuse Octopy\\Impersonate\\Concerns\\HasImpersonation;\nuse Octopy\\Impersonate\\Contracts\\HasImpersonationUI;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable implements HasImpersonationUI\n{\n    use HasImpersonation;\n    \n    /**\n     * @return string\n     */\n    public function getImpersonateDisplayText() : string\n    {\n        return $this-\u003ename;\n    }\n    \n    /**\n     * This following is useful for performing user searches through the interface,\n     * You can use fields in relations freely using dot notation,\n     * \n     * example: posts.title, department.name.   \n     */\n    public function getImpersonateSearchField() : array\n    {\n        return [\n            'name', 'posts.title',\n        ];\n    }\n}\n\n```\n\n## Events\n\nThere are two events available that can be used to improve your workflow:\n\n- `Octopy\\Impersonate\\Events\\BeginImpersonation` is fired when an impersonation is begin.\n- `Octopy\\Impersonate\\Events\\LeaveImpersonation` is fired when an impersonation is leave.\n\n## Configuration\n\nThis configuration is intended to customize the appearance of Laravel Impersonate, if you don't need a UI, don't forget to set `IMPERSONATE_ENABLED` to `false` in your environment\nfile because it is enabled by default.\n\nPlease refer to the [impersonate.php](config/impersonate.php) file to see the available configurations.\n\n## Usage\n\n### Basic Usage\n\nBy default, you don't need to do anything, but keep in mind, Impersonation can be done by anyone if you don't define the rules of who can do impersonation or who can be\nimpersonated.\n\n#### Defining Limitation\n\nTo limit who can do **impersonation** or who is can be **impersonated**, add\n`setImpersonateAuthorization(Authorization $authorization)` on the Model to enforce the limitation.\n\nThe **impersonator** method is intended for who can perform the impersonation and the **impersonated** method is intended for anyone who is allowed to be imitated.\n\n\u003e **Warning**\n\u003e\n\u003e Not defining the Authorization rules in the Model or misdefining them can lead to serious security issues.\n\nThe example below uses [Laratrust](https://github.com/santigarcor/laratrust/) for role management where **SUPER_ADMIN** can perform impersonation against **CUSTOMER**. Feel\nfree to use any other Role Management you like.\n\n```php\nuse Octopy\\Impersonate\\Concerns\\HasImpersonation;\nuse Octopy\\Impersonate\\Authorization;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable\n{\n    use HasImpersonation;\n    \n    /**\n     * @param  Authorization $authorization\n     * @return void\n     */\n    public function setImpersonateAuthorization(Authorization $authorization) : void\n    {\n        $authorization-\u003eimpersonator(function (User $user) {\n            return $user-\u003ehasRole('SUPER_ADMIN');\n        });\n\n        $authorization-\u003eimpersonated(function (User $user) {\n            return $user-\u003ehasRole('CUSTOMER');\n        });\n    }\n}\n```\n\n### Advanced Usage\n\n#### Impersonating User Manually\n\nSometimes you need Impersonating manually, to perform it, you can use the impersonate singleton.\n\n```php\nimpersonate()-\u003ebegin($admin, $customer);\n```\n\nOr just simply call the impersonation method directly through the User Model.\n\n```php\n$admin-\u003eimpersonate($customer);\n```\n\n#### Defining Guard\n\nSometimes, you want to use custom guards for authentication, instead of the built-in guards.\n\n```php\nimpersonate()-\u003eguard('foo')-\u003ebegin($admin, $customer);\n```\n\n#### Leaving Impersonation Mode\n\nTo leave Impersonation mode, you just need to call the `leave` method on impersonate singleton. This will return you to the original user.\n\n```php\nimpersonate()-\u003eleave();\n```\n\nOr via Model directly\n\n```php\n$admin-\u003eimpersonate()-\u003eleave();\n```\n\nDon't hesitate to use a guard if you need it.\n\n## Disclaimer\n\nThis package can pose a serious security issue if used incorrectly, as anybody will be able to take control of any user's account.\n\nBy using this package, you agree that Octopy ID and the contributors of this package cannot be held responsible for any damages caused by using this package.\n\n## Security\n\nIf you discover any security related issues, please email [bug@octopy.dev](mailto:bug@octopy.dev) instead of using the issue\ntracker.\n\n## Credits\n\n- [Supian M](https://github.com/SupianIDz)\n- [Octopy ID](https://github.com/OctopyID)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","funding_links":["https://github.com/sponsors/SupianIDz","https://ko-fi.com/SupianIDz"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctopyid%2Flarapersonate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctopyid%2Flarapersonate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctopyid%2Flarapersonate/lists"}