PHP code example of codicastudio / impersonate-manager
1. Go to this page and download the library: Download codicastudio/impersonate-manager 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/ */
codicastudio / impersonate-manager 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)->withMeta([
'hideText' => false,
]),
// or
Impersonate::make($this)->withMeta([
'redirect_to' => '/custom-redirect-url'
]),
];
}
...
}
/**
* @return bool
*/
public function canImpersonate()
{
// For example
return $this->is_admin == 1;
}
/**
* @return bool
*/
public function canBeImpersonated()
{
// For example
return $this->can_be_impersonated == 1;
}
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
],
];