### Install Filament Impersonate via Composer Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This command installs the Filament Impersonate plugin using Composer, the dependency manager for PHP. Ensure you have Composer installed and configured for your project. ```bash composer require stechstudio/filament-impersonate ``` -------------------------------- ### Configure Impersonate Action with Guard and Redirect Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This example shows how to customize the Impersonate action by specifying a different authentication guard and a custom redirect route. This allows for more flexible integration with different authentication setups. ```php Impersonate::make('impersonate') ->guard('another-guard') ->redirectTo(route('some.other.route')); ``` -------------------------------- ### Implement Target Authorization for Impersonation Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This PHP code demonstrates how to implement the `canBeImpersonated` method in a user model to control which users can be impersonated. This example prevents impersonating users from a specific company. ```php class User { public function canBeImpersonated() { // Let's prevent impersonating other users at our own company return !Str::endsWith($this->email, '@mycorp.com'); } } ``` -------------------------------- ### Customize Impersonation Banner Style Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This example demonstrates how to customize the appearance of the impersonation banner by setting its style attribute. You can choose between 'light', 'dark' (default), or 'auto' for the banner's theme. ```html ``` -------------------------------- ### Implement User Authorization for Impersonation Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This PHP code shows how to implement the `canImpersonate` method in your Filament user model to control which users can impersonate others. Returning `true` allows impersonation, while `false` denies it. ```php class User implements FilamentUser { public function canImpersonate() { return true; } } ``` -------------------------------- ### Add Table Action for Impersonation in Filament Resource Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This PHP code snippet demonstrates how to add the 'Impersonate' action to a Filament resource's table. It's typically added within the `table` method of a resource class, like `UserResource`, to provide an impersonate button next to each record. ```php namespace App\Filament\Resources; use Filament\Resources\Resource; use STS\FilamentImpersonate\Tables\Actions\Impersonate; class UserResource extends Resource { public static function table(Table $table) { return $table ->columns([ // ... ]) ->actions([ Impersonate::make(), // <--- ]); } } ``` -------------------------------- ### Add Page Action for Impersonation in Filament Resource Page Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This PHP code demonstrates adding the 'Impersonate' action to a specific page within a Filament resource, such as an edit page. It's added in the `getActions` method and requires passing the current record to the action. ```php record($this->getRecord()) // <-- ]; } } ``` -------------------------------- ### Prevent 403 in UserPolicy with Impersonation Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This PHP code snippet demonstrates how to add a guard clause to the `UserPolicy::viewAny()` method to prevent a 403 error when impersonating users. It checks if the current user is impersonating and returns true if so, avoiding conflicts with Livewire component re-renders and policy checks. ```php isImpersonating()) { return true; } // ... Any other checks here } ``` -------------------------------- ### Include Impersonation Banner in Blade Layout Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This HTML snippet shows how to include the impersonation banner component in your application's master Blade layout. This banner provides a notice and a button to return to Filament when impersonating a user on non-Filament pages. ```blade ``` -------------------------------- ### Customize Impersonate Banner Display Name Source: https://github.com/stechstudio/filament-impersonate/blob/master/README.md This snippet shows how to customize the display name shown in the impersonate banner by providing a custom value to the `:display` attribute. It assumes the `name` attribute is available or uses an alternative like the user's email. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.