Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| User | |
0.00% |
0 / 21 |
|
0.00% |
0 / 9 |
210 | |
0.00% |
0 / 1 |
| Image | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| Activity_logs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getImage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getRole | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getRoleId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getCreatedAtAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| has_permission | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getJWTIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getJWTCustomClaims | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Traits\helper; |
| 6 | use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 7 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 8 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 9 | use Illuminate\Foundation\Auth\User as Authenticatable; |
| 10 | use Illuminate\Notifications\Notifiable; |
| 11 | use Laravel\Sanctum\HasApiTokens; |
| 12 | use Laratrust\Traits\LaratrustUserTrait; |
| 13 | use Tymon\JWTAuth\Contracts\JWTSubject; |
| 14 | |
| 15 | |
| 16 | class User extends Authenticatable implements JWTSubject |
| 17 | { |
| 18 | use LaratrustUserTrait; |
| 19 | use HasApiTokens, HasFactory, Notifiable, SoftDeletes; |
| 20 | use helper; |
| 21 | |
| 22 | protected $table = 'users'; |
| 23 | |
| 24 | protected $guarded = []; |
| 25 | |
| 26 | protected $hidden = [ |
| 27 | 'password', |
| 28 | 'remember_token', |
| 29 | ]; |
| 30 | |
| 31 | /** |
| 32 | * The attributes that should be cast. |
| 33 | * |
| 34 | * @var array<string, string> |
| 35 | */ |
| 36 | protected $casts = [ |
| 37 | 'verified_at' => 'datetime', |
| 38 | ]; |
| 39 | |
| 40 | //relations |
| 41 | public function Image() |
| 42 | { |
| 43 | return $this->morphOne(Image::class, 'imageable'); |
| 44 | } |
| 45 | |
| 46 | public function Activity_logs() |
| 47 | { |
| 48 | return $this->morphMany(Activity_log::class, 'causer'); |
| 49 | } |
| 50 | |
| 51 | // |
| 52 | public function getImage(){ |
| 53 | if($this->Image != null){ |
| 54 | return url('uploads/users/' . $this->Image->src); |
| 55 | } else { |
| 56 | return url('uploads/users/default.jpg'); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public function getRole(){ |
| 61 | if(count($this->roles) > 0){ |
| 62 | return $this->roles[0]->name; |
| 63 | } else { |
| 64 | return null; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public function getRoleId(){ |
| 69 | if(count($this->roles) > 0){ |
| 70 | return $this->roles[0]->id; |
| 71 | } else { |
| 72 | return null; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public function getCreatedAtAttribute(){ |
| 77 | return $this->date_format($this->attributes['created_at']); |
| 78 | } |
| 79 | |
| 80 | public function has_permission($permission){ |
| 81 | if($this->super == 1) |
| 82 | return true; |
| 83 | |
| 84 | if($this->isAbleTo($permission)) |
| 85 | return true; |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | /** |
| 92 | * Get the identifier that will be stored in the subject claim of the JWT. |
| 93 | * |
| 94 | * @return mixed |
| 95 | */ |
| 96 | public function getJWTIdentifier() |
| 97 | { |
| 98 | return $this->getKey(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Return a key value array, containing any custom claims to be added to the JWT. |
| 103 | * |
| 104 | * @return array |
| 105 | */ |
| 106 | public function getJWTCustomClaims() |
| 107 | { |
| 108 | return [ |
| 109 | 'type' => 'user_api' |
| 110 | ]; |
| 111 | } |
| 112 | } |