/
Impersonable.php
62 lines (53 loc) · 1.06 KB
/
Impersonable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace LaraComponents\Impersonation\Traits;
use Illuminate\Support\Facades\Session;
trait Impersonable
{
/**
* Start impersonating this user.
*
* @return $this
*/
public function impersonate()
{
Session::put($this->getImpersonatingKey(), $this->getKey());
return $this;
}
/**
* Stop impersonating.
*
* @return $this
*/
public function unimpersonate()
{
Session::forget($this->getImpersonatingKey());
return $this;
}
/**
* Check if user is impersonating.
*
* @return bool
*/
public function isImpersonating()
{
return Session::has($this->getImpersonatingKey());
}
/**
* Get impersonating user id.
*
* @return int
*/
public function getImpersonatingId()
{
return Session::get($this->getImpersonatingKey());
}
/**
* Get impersonating key.
*
* @return string
*/
public function getImpersonatingKey()
{
return 'impersonate_id';
}
}