1. Go to this page and download the library: Download kabbouchi/nova-impersonate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kabbouchi / nova-impersonate example snippets
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('ng', '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'
]),
];
}
...
}
/**
* @return bool
*/
public function canImpersonate($impersonated = null)
{
// For example
return $this->is_admin == 1;
}
/**
* @return bool
*/
public function canBeImpersonated(?\Illuminate\Contracts\Auth\Authenticatable $impersonator = null)
{
// For example
return $this->can_be_impersonated == 1;
}
/**
* @return string
*/
public function impersonateName()
{
// For example
return $this->email;
}
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
],
];