|
1
|
|
|
<?php namespace App\Modules\V1\Acl; |
|
2
|
|
|
|
|
3
|
|
|
use App\User; |
|
4
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
5
|
|
|
use Illuminate\Notifications\Notifiable; |
|
6
|
|
|
use Laravel\Passport\HasApiTokens; |
|
7
|
|
|
|
|
8
|
|
|
class AclUser extends User { |
|
9
|
|
|
|
|
10
|
|
|
use SoftDeletes, HasApiTokens; |
|
11
|
|
|
protected $table = 'users'; |
|
12
|
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
13
|
|
|
protected $hidden = ['password', 'remember_token','deleted_at']; |
|
14
|
|
|
protected $guarded = ['id']; |
|
15
|
|
|
protected $fillable = ['name', 'email', 'password']; |
|
16
|
|
|
public $searchable = ['name', 'email']; |
|
17
|
|
|
|
|
18
|
|
|
public function getCreatedAtAttribute($value) |
|
19
|
|
|
{ |
|
20
|
|
|
return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getUpdatedAtAttribute($value) |
|
24
|
|
|
{ |
|
25
|
|
|
return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getDeletedAtAttribute($value) |
|
29
|
|
|
{ |
|
30
|
|
|
return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Encrypt the password attribute before |
|
35
|
|
|
* saving it in the storage. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $value |
|
38
|
|
|
*/ |
|
39
|
|
|
public function setPasswordAttribute($value) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->attributes['password'] = bcrypt($value); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function groups() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Return fcm device tokens related to the user. |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
|
public function routeNotificationForFCM() |
|
54
|
|
|
{ |
|
55
|
|
|
$devices = \Core::pushNotificationsDevices()->findBy(['user_id' => $this->id]); |
|
56
|
|
|
$tokens = []; |
|
57
|
|
|
|
|
58
|
|
|
foreach ($devices as $device) |
|
59
|
|
|
{ |
|
60
|
|
|
$accessToken = decrypt($device->access_token); |
|
61
|
|
|
|
|
62
|
|
|
try |
|
63
|
|
|
{ |
|
64
|
|
|
if (\Core::users()->accessTokenExpiredOrRevoked($accessToken)) |
|
65
|
|
|
{ |
|
66
|
|
|
continue; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$tokens[] = $device->device_token; |
|
70
|
|
|
} |
|
71
|
|
|
catch (\Exception $e) |
|
72
|
|
|
{ |
|
73
|
|
|
$device->forceDelete(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $tokens; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* The channels the user receives notification broadcasts on. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function receivesBroadcastNotificationsOn() |
|
86
|
|
|
{ |
|
87
|
|
|
return 'users.' . $this->id; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public static function boot() |
|
91
|
|
|
{ |
|
92
|
|
|
parent::boot(); |
|
93
|
|
|
parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.