dominikkukacka / nova-impersonate
Laravel Nova 字段允许您以您的用户身份进行身份验证。
2.0
2022-02-01 10:20 UTC
Requires
- php: >=7.1.0
- lab404/laravel-impersonate: ^1.7.3
- dev-master
- 2.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/npm_and_yarn/url-parse-1.5.3
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.8
This package is auto-updated.
Last update: 2024-09-29 06:20:27 UTC
README
此字段允许您以您的用户身份进行身份验证。
幕后使用 404labfr/laravel-impersonate。
安装
您可以通过 composer 将此包安装到使用 Nova 的 Laravel 应用程序中
composer require kabbouchi/nova-impersonate
用法
在 App\Nova\User.php
中添加 Impersonate::make($this)
字段
<?php namespace App\Nova; use KABBOUCHI\NovaImpersonate\Impersonate; ... class User extends Resource { ... public function fields(Request $request) { return [ ID::make()->sortable(), Gravatar::make(), Text::make('Name') ->sortable() ->rules('required', 'max:255'), Text::make('Email') ->sortable() ->rules('required', 'email', 'max:255') ->creationRules('unique:users,email') ->updateRules('unique:users,email,{{resourceId}}'), Password::make('Password') ->onlyOnForms() ->creationRules('required', 'string', 'min:6') ->updateRules('nullable', 'string', 'min:6'), Impersonate::make($this), // <--- // or Impersonate::make($this->resource), // works in lenses // or Impersonate::make($this)->withMeta([ 'hideText' => false, ]), // or Impersonate::make($this)->withMeta([ 'redirect_to' => '/custom-redirect-url' ]), ]; } ... }
高级用法
默认情况下,所有用户都可以 模拟 一个用户。
您需要将方法 canImpersonate()
添加到您的用户模型中
/** * @return bool */ public function canImpersonate($impersonated = null) { // For example return $this->is_admin == 1; }
默认情况下,所有用户都可以 被模拟。
您需要将方法 canBeImpersonated()
添加到您的用户模型中以扩展此行为:请确保传递实例模型或 Nova 资源 Impersonate::make($this)
Impersonate::make($this->resource)
/** * @return bool */ public function canBeImpersonated(?\Illuminate\Contracts\Auth\Authenticatable $impersonator = null) { // For example return $this->can_be_impersonated == 1; }
事件
您可以挂钩到底层包的事件
可能对设置会话数据等操作有用
Lab404\Impersonate\Events\TakeImpersonation
Lab404\Impersonate\Events\LeaveImpersonation
您可以选择使用以下命令发布配置文件
php artisan vendor:publish --tag=nova-impersonate-config
这是在 config/nova-impersonate.php
中发布的配置文件的默认内容
<?php return [ 'enable_middleware' => true, // To inject the 'nova-impersonate::reverse' view in every route when impersonating 'redirect_back' => true, // false (nova path), true or <url> 'redirect_to' => '/', 'key_down' => 'i', // Press `i` to impersonate user in details page 'middleware' => [ 'base' => 'web', // Middleware used for nova-impersonate routes 'leave' => 'auth', // Extra middleware used for leave route ], ];
您可以通过以下命令发布和自定义 nova-impersonate::reverse
视图
php artisan vendor:publish --tag=nova-impersonate-views
致谢
MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。