• Stars
    star
    230
  • Rank 168,455 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Laravel Nova field allows you to authenticate as your users.

Nova Impersonate Field

Latest Version on Packagist Total Downloads

This field allows you to authenticate as your users.

screenshot1 screenshot2 screenshot3

Behind the scenes 404labfr/laravel-impersonate is used.

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require kabbouchi/nova-impersonate

Usage

Add Impersonate::make($this) field in App\Nova\User.php

<?php

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('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'),


			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'
			]),

		];
	}

    ...
}

Advanced Usage

By default all users can impersonate an user.
You need to add the method canImpersonate() to your user model:

    /**
     * @return bool
     */
    public function canImpersonate($impersonated = null)
    {
        // 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 Impersonate::make($this) Impersonate::make($this->resource)

    /**
     * @return bool
     */
    public function canBeImpersonated(?\Illuminate\Contracts\Auth\Authenticatable $impersonator = null)
    {
        // For example
        return $this->can_be_impersonated == 1;
    }

By default name field is used for when displaying what user is impersonated at a moment. You need to add the method impersonateName() to your user model to extend this behavior: Please make sure to pass instance Model or Nova Resource Impersonate::make($this) Impersonate::make($this->resource)

    /**
     * @return string
     */
    public function impersonateName()
    {
        // For example
        return $this->email;
    }

Events

You can hook onto the underlying package events

May be userful for things like setting session data

  • Lab404\Impersonate\Events\TakeImpersonation
  • Lab404\Impersonate\Events\LeaveImpersonation

You can optionally publish the config file with:

php artisan vendor:publish --tag=nova-impersonate-config

This is the default content of the config file published at config/nova-impersonate.php:

<?php

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
    ],
];

You can publish and customize the nova-impersonate::reverse view

php artisan vendor:publish --tag=nova-impersonate-views

Credits

The MIT License (MIT). Please see License File for more information.

More Repositories

1

vue-tippy

VueJS Tooltip powered by Tippy.js
TypeScript
664
star
2

nova-logs-tool

A Laravel Nova tool to manage and keep track of each one of your logs files.
Vue
71
star
3

laravel-mix-merge-manifest

This extension support multi mix configration without overwriting the mix-manifest.json file
JavaScript
60
star
4

laravel-ward

Manage Your Laravel Log From A Web Dashboard
JavaScript
24
star
5

laravel-mix-vue3

A Laravel Mix extension for Vue 3, Typescript and JSX.
JavaScript
23
star
6

laravel-logger-discord-channel

A Discord based Monolog driver for Laravel
PHP
13
star
7

adonisjs-scheduler

Task scheduler for AdonisJS
TypeScript
13
star
8

vue-slugify

Slug directive plugin for Vue.js
JavaScript
9
star
9

laravel-bread

Build a custom admin interface for your Eloquent models
PHP
8
star
10

laravel-table-view

Laravel 5 Package for easily displaying table views for Eloquent Collections
PHP
7
star
11

flutter_laravel_forge

A Laravel Forge mobile app.
Dart
6
star
12

laravel-vercel

Laravel Vercel - Adapter/Bridge
PHP
5
star
13

laravel-mix-vue-auto-routing

A quick Laravel Mix extension to generate "Vue Router" routing automatically.
JavaScript
5
star
14

nuxt-vue-web3

Vue
4
star
15

flutter_fast_route

fast_route is a custom Flutter routing library inspired by vue-router.
Dart
3
star
16

nuxt3-vue-web3

Vue
2
star
17

simple-mvc

A Simple PHP Framework
PHP
2
star
18

konsole

Konsole is command line interface for Unity.
C#
2
star
19

laravel-settings

Advanced Settings Manager for Laravel
PHP
2
star
20

laravel-mix-register-aliases

A quick Laravel Mix extension to register aliases (~,@).
JavaScript
2
star
21

provisioner

PHP
1
star
22

vue-inline-data

JavaScript
1
star
23

nuxt-nitro-helpers

TypeScript
1
star
24

awesome-vue-renderer

Awesome list of Vue Renderer
1
star
25

AgarDarkRift-MasterServer

C#
1
star
26

etherscan-token-holders

TypeScript
1
star
27

docus-starter

Starter for Docus.dev
JavaScript
1
star
28

BigNumber.php

A PHP package for arbitrary-precision decimal and non-decimal arithmetic inspired by bignumber.js
PHP
1
star
29

date-countdown-component

https://kabbouchi.github.io/date-countdown-component
Vue
1
star
30

nova-impersonate-test

PHP
1
star