PHP code example of xlite-dev / filament-impersonate
1. Go to this page and download the library: Download xlite-dev/filament-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/ */
xlite-dev / filament-impersonate example snippets
namespace App\Filament\Resources;
use Filament\Resources\Resource;
use XliteDev\FilamentImpersonate\Tables\Actions\ImpersonateAction; // <---
class UserResource extends Resource {
// ...
public static function table(Table $table)
{
return $table
->columns([
// ...
])
->actions([
ImpersonateAction::make(), // <---
// ...
]);
}
namespace App\Filament\Resources;
use Filament\Resources\Resource;
use XliteDev\FilamentImpersonate\Pages\Actions\ImpersonateAction; // <---
class EditUser extends ViewRecord
{
// ...
protected function getActions(): array
{
return [
ImpersonateAction::make()->record($this->getRecord()), // <---
// ...
];
}
return [
// This is the guard used when logging in as the impersonated user.
'guard' => env('FILAMENT_IMPERSONATE_GUARD', 'web'),
// After impersonating this is where we'll redirect you to.
'redirect_to' => env('FILAMENT_IMPERSONATE_REDIRECT', '/'),
// We wire up a route for the "leave" button. You can change the middleware stack here if needed.
'leave_middlewares' => [
env('FILAMENT_IMPERSONATE_LEAVE_MIDDLEWARE', 'web'),
],
'banner' => [
// Currently supports 'dark' and 'light'.
'style' => env('FILAMENT_IMPERSONATE_BANNER_STYLE', 'dark'),
// Turn this off if you want `absolute` positioning, so the banner scrolls out of view
'fixed' => env('FILAMENT_IMPERSONATE_BANNER_FIXED', true),
// Currently supports 'top' and 'bottom'.
'position' => env('FILAMENT_IMPERSONATE_BANNER_POSITION', 'top'),
],
];
class User implements FilamentUser {
public function canImpersonate()
{
return true;
}
}
class User {
public function canBeImpersonated()
{
// Let's prevent impersonating other users at our own company
return !Str::endsWith($this->email, '@mycorp.com');
}
}