lucacri/spark-impersonate

一个 Laravel Nova 字段,允许您通过 Spark 验证为您的用户。

安装数: 17,866

依赖: 0

建议者: 0

安全: 0

星标: 12

关注者: 3

分支: 1

开放问题: 8

语言:Vue

0.0.4 2019-10-17 20:28 UTC

README

此字段允许您通过 Spark 验证为您的用户。

screenshot1 screenshot2 screenshot3

从美丽的包 KABBOUCHI/nova-impersonate 分支。

安装

您可以通过 composer 在使用 Nova 的 Laravel 应用中安装此包

composer require lucacri/spark-impersonate

使用方法

App\Nova\User.php 中添加 SparkImpersonate::make($this) 字段

<?php

namespace App\Nova;

use Lucacri\SparkImpersonate\SparkImpersonate;

...

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'),


			SparkImpersonate::make($this),  // <---
		
			// or
		
			SparkImpersonate::make($this)->withMeta([
			    'hideText' => false,
			]),
		

		];
	}

    ...
}

高级使用

默认情况下,所有用户都可以 模拟 用户。
您需要向您的用户模型添加方法 canImpersonate()

    /**
     * @return bool
     */
    public function canImpersonate()
    {
        // For example
        return $this->is_admin == 1;
    }

默认情况下,所有用户都可以 被模拟
您需要向您的用户模型添加方法 canBeImpersonated() 以扩展此行为:请确保传递实例模型或 Nova 资源 SparkImpersonate::make($this) SparkImpersonate::make($this->resource)

    /**
     * @return bool
     */
    public function canBeImpersonated()
    {
        // For example
        return $this->can_be_impersonated == 1;
    }

致谢

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件