kabbouchi / nova-impersonate
Laravel Nova 字段允许您以用户身份进行认证。
v2.0.0
2022-05-08 20:30 UTC
Requires
- lab404/laravel-impersonate: ^1.7.3
- laravel/nova: ^4.0
- dev-master
- v2.0.0
- v1.x-dev
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.0
- v1.11.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/elliptic-6.5.4
This package is auto-updated.
Last update: 2024-09-18 22:41:12 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; }
默认情况下使用 name
字段来显示某一刻正在模拟的用户。您需要向您的用户模型添加 impersonateName()
方法以扩展此行为:请确保传递实例模型或 Nova 资源 Impersonate::make($this)
Impersonate::make($this->resource)
/** * @return string */ public function impersonateName() { // For example return $this->email; }
事件
您可以将钩子连接到底层包的事件
这可能对设置会话数据等问题很有用
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)。有关更多信息,请参阅 许可文件