{"id":19632993,"url":"https://github.com/kabbouchi/nova-impersonate","last_synced_at":"2025-05-14T18:07:45.615Z","repository":{"id":32966082,"uuid":"148044312","full_name":"KABBOUCHI/nova-impersonate","owner":"KABBOUCHI","description":"A Laravel Nova field allows you to authenticate as your users.","archived":false,"fork":false,"pushed_at":"2025-04-14T08:24:55.000Z","size":1953,"stargazers_count":233,"open_issues_count":18,"forks_count":38,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-14T09:53:01.371Z","etag":null,"topics":["impersonate","laravel","nova"],"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/KABBOUCHI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2018-09-09T16:31:05.000Z","updated_at":"2025-04-14T08:23:30.000Z","dependencies_parsed_at":"2025-02-02T17:00:52.161Z","dependency_job_id":"fa929cc6-7364-468f-83f0-cab9bbf17d0d","html_url":"https://github.com/KABBOUCHI/nova-impersonate","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fnova-impersonate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fnova-impersonate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fnova-impersonate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KABBOUCHI%2Fnova-impersonate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KABBOUCHI","download_url":"https://codeload.github.com/KABBOUCHI/nova-impersonate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030966,"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","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":["impersonate","laravel","nova"],"created_at":"2024-11-11T12:15:56.998Z","updated_at":"2025-05-14T18:07:40.599Z","avatar_url":"https://github.com/KABBOUCHI.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nova Impersonate Field\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/kabbouchi/nova-impersonate.svg?style=flat-square)](https://packagist.org/packages/kabbouchi/nova-impersonate)\n[![Total Downloads](https://img.shields.io/packagist/dt/kabbouchi/nova-impersonate.svg?style=flat-square)](https://packagist.org/packages/kabbouchi/nova-impersonate)\n\n\nThis field allows you to authenticate as your users.\n\n![screenshot1](https://raw.githubusercontent.com/KABBOUCHI/nova-impersonate/master/docs/screenshot1.png?123)\n![screenshot2](https://raw.githubusercontent.com/KABBOUCHI/nova-impersonate/master/docs/screenshot2.png?123)\n![screenshot3](https://raw.githubusercontent.com/KABBOUCHI/nova-impersonate/master/docs/screenshot3.png?123)\n\nBehind the scenes [404labfr/laravel-impersonate](https://github.com/404labfr/laravel-impersonate) is used.\n\n## Installation\n\nYou can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:\n\n```bash\ncomposer require kabbouchi/nova-impersonate\n```\n\n## Usage\n\nAdd `Impersonate::make($this)` field in `App\\Nova\\User.php`\n```php\n\u003c?php\n\nnamespace App\\Nova;\n\nuse KABBOUCHI\\NovaImpersonate\\Impersonate;\n\n...\n\nclass User extends Resource\n{\n\t...\n\t\n\tpublic function fields(Request $request)\n\t{\n\t\treturn [\n\t\t\tID::make()-\u003esortable(),\n\n\t\t\tGravatar::make(),\n\n\t\t\tText::make('Name')\n\t\t\t\t-\u003esortable()\n\t\t\t\t-\u003erules('required', 'max:255'),\n\n\t\t\tText::make('Email')\n\t\t\t\t-\u003esortable()\n\t\t\t\t-\u003erules('required', 'email', 'max:255')\n\t\t\t\t-\u003ecreationRules('unique:users,email')\n\t\t\t\t-\u003eupdateRules('unique:users,email,{{resourceId}}'),\n\n\t\t\tPassword::make('Password')\n\t\t\t\t-\u003eonlyOnForms()\n\t\t\t\t-\u003ecreationRules('required', 'string', 'min:6')\n\t\t\t\t-\u003eupdateRules('nullable', 'string', 'min:6'),\n\n\n\t\t\tImpersonate::make($this),  // \u003c---\n\t\t\n\t\t\t// or\n            \n            Impersonate::make($this-\u003eresource), // works in lenses\n            \n            // or\n\t\t\n\t\t\tImpersonate::make($this)-\u003ewithMeta([\n\t\t\t    'hideText' =\u003e false,\n\t\t\t]),\n\t\t\n\t\t\t// or\n\t\t\n\t\t\tImpersonate::make($this)-\u003ewithMeta([\n\t\t\t    'redirect_to' =\u003e '/custom-redirect-url'\n\t\t\t]),\n\n\t\t];\n\t}\n\n    ...\n}\n```\n\n## Advanced Usage\n\nBy default all users can **impersonate** an user.  \nYou need to add the method `canImpersonate()` to your user model:\n\n```php\n    /**\n     * @return bool\n     */\n    public function canImpersonate($impersonated = null)\n    {\n        // For example\n        return $this-\u003eis_admin == 1;\n    }\n```\n\nBy default all users can **be impersonated**.  \nYou need to add the method `canBeImpersonated()` to your user model to extend this behavior:\nPlease make sure to pass instance Model or Nova Resource ``Impersonate::make($this)`` ``Impersonate::make($this-\u003eresource)``\n\n```php\n    /**\n     * @return bool\n     */\n    public function canBeImpersonated(?\\Illuminate\\Contracts\\Auth\\Authenticatable $impersonator = null)\n    {\n        // For example\n        return $this-\u003ecan_be_impersonated == 1;\n    }\n```\n\nBy default `name` field is used for when displaying what user is impersonated at a moment.\nYou need to add the method `impersonateName()` to your user model to extend this behavior:\nPlease make sure to pass instance Model or Nova Resource ``Impersonate::make($this)`` ``Impersonate::make($this-\u003eresource)``\n\n```php\n    /**\n     * @return string\n     */\n    public function impersonateName()\n    {\n        // For example\n        return $this-\u003eemail;\n    }\n```\n---\n\n#### Events\n\nYou can hook onto the underlying package events\n\nMay be userful for things like setting session data\n\n- `Lab404\\Impersonate\\Events\\TakeImpersonation`\n- `Lab404\\Impersonate\\Events\\LeaveImpersonation`\n\n---\n\nYou can optionally publish the config file with:\n```bash\nphp artisan vendor:publish --tag=nova-impersonate-config\n```\n\nThis is the default content of the config file published at `config/nova-impersonate.php`:\n```php\n\u003c?php\n\nreturn [\n\t'enable_middleware' =\u003e true, // To inject the 'nova-impersonate::reverse' view in every route when impersonating \n\t'redirect_back'     =\u003e true, // false (nova path), true or \u003curl\u003e\n\t'redirect_to'       =\u003e '/',\n\t'key_down'          =\u003e 'i', // Press `i` to impersonate user in details page\n\t'middleware'        =\u003e [\n            'base' =\u003e 'web', // Middleware used for nova-impersonate routes\n            'leave'  =\u003e 'auth', // Extra middleware used for leave route\n    ],\n];\n```\n\nYou can publish and customize the `nova-impersonate::reverse` view\n\n```bash\nphp artisan vendor:publish --tag=nova-impersonate-views\n```\n\n\n## Credits\n\n- [Georges KABBOUCHI](https://github.com/kabbouchi)\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabbouchi%2Fnova-impersonate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkabbouchi%2Fnova-impersonate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkabbouchi%2Fnova-impersonate/lists"}