This field allows you to authenticate as your users via Spark.
Forked from the beautiful package KABBOUCHI/nova-impersonate.
You can install the package in to a Laravel app that uses Nova via composer:
composer require lucacri/spark-impersonate
Add SparkImpersonate::make($this)
field in App\Nova\User.php
<?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,
]),
];
}
...
}
By default all users can impersonate an user.
You need to add the method canImpersonate()
to your user model:
/**
* @return bool
*/
public function canImpersonate()
{
// For example
return $this->is_admin == 1;
}
By default all users can be impersonated.
You need to add the method canBeImpersonated()
to your user model to extend this behavior:
Please make sure to pass instance Model or Nova Resource SparkImpersonate::make($this)
SparkImpersonate::make($this->resource)
/**
* @return bool
*/
public function canBeImpersonated()
{
// For example
return $this->can_be_impersonated == 1;
}
The MIT License (MIT). Please see License File for more information.