codicastudio / impersonate-manager
一个随机的Codica Studio软件包。
1.0.0
2020-09-25 01:50 UTC
Requires
- php: ^7.4 || ^8.0
- codicastudio/impersonate: ^1.0
This package is auto-updated.
Last update: 2024-09-25 13:15:52 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)->withMeta([ 'hideText' => false, ]), // or Impersonate::make($this)->withMeta([ 'redirect_to' => '/custom-redirect-url' ]), ]; } ... }
高级使用
默认情况下,所有用户都可以伪装其他用户。
您需要将方法canImpersonate()
添加到您的用户模型中。
/** * @return bool */ public function canImpersonate() { // For example return $this->is_admin == 1; }
默认情况下,所有用户都可以被伪装。
您需要将方法canBeImpersonated()
添加到您的用户模型中,以扩展此行为:请确保传递实例模型或Nova资源Impersonate::make($this)
Impersonate::make($this->resource)
/** * @return bool */ public function canBeImpersonated() { // 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)。请参阅许可证文件以获取更多信息。