|
1
|
|
|
<?php namespace Arcanesoft\Auth\Models; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\LaravelAuth\Models\User as BaseUserModel; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class User |
|
7
|
|
|
* |
|
8
|
|
|
* @package Arcanesoft\Auth\Models |
|
9
|
|
|
* @author ARCANEDEV <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @property string gravatar |
|
12
|
|
|
*/ |
|
13
|
|
|
class User extends BaseUserModel |
|
14
|
|
|
{ |
|
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
| Getters & Setters |
|
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
18
|
|
|
*/ |
|
19
|
|
|
/** |
|
20
|
|
|
* Get the user hash id. |
|
21
|
|
|
* |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getHashedIdAttribute() |
|
25
|
|
|
{ |
|
26
|
|
|
return hasher()->encode($this->id); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the full name attribute or use the username if empty. |
|
31
|
|
|
* |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getFullNameAttribute() |
|
35
|
|
|
{ |
|
36
|
|
|
$fullName = trim($this->first_name . ' ' . $this->last_name); |
|
37
|
|
|
|
|
38
|
|
|
return empty($fullName) ? $this->username : $fullName; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get the gravatar attribute. |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getGravatarAttribute() |
|
47
|
|
|
{ |
|
48
|
|
|
return gravatar() |
|
49
|
|
|
->setDefaultImage('mm')->setSize(160) |
|
50
|
|
|
->src($this->email); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get the since date attribute (translated). |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getSinceDateAttribute() |
|
59
|
|
|
{ |
|
60
|
|
|
return trans('auth::users.since', [ |
|
61
|
|
|
'date' => $this->created_at->toFormattedDateString() |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
66
|
|
|
| Main Function |
|
67
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
68
|
|
|
*/ |
|
69
|
|
|
/** |
|
70
|
|
|
* Get a user from a hashed id or fail if not found. |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $hashedId |
|
73
|
|
|
* |
|
74
|
|
|
* @return self |
|
75
|
|
|
* |
|
76
|
|
|
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
|
77
|
|
|
*/ |
|
78
|
|
|
public static function firstHashedOrFail($hashedId) |
|
79
|
|
|
{ |
|
80
|
|
|
$id = head(hasher()->decode($hashedId)); |
|
81
|
|
|
|
|
82
|
|
|
return self::withTrashed() |
|
|
|
|
|
|
83
|
|
|
->where('id', $id) |
|
84
|
|
|
->firstOrFail(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
88
|
|
|
| Check Functions |
|
89
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
90
|
|
|
*/ |
|
91
|
|
|
/** |
|
92
|
|
|
* Check if user is an administrator. |
|
93
|
|
|
* |
|
94
|
|
|
* @return bool |
|
95
|
|
|
*/ |
|
96
|
|
|
public function isAdmin() |
|
97
|
|
|
{ |
|
98
|
|
|
return parent::isAdmin() || $this->is('administrator'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: