These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Encore\Admin\Auth\Database; |
||
4 | |||
5 | use Encore\Admin\Traits\AdminBuilder; |
||
6 | use Illuminate\Auth\Authenticatable; |
||
7 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
||
8 | use Illuminate\Database\Eloquent\Model; |
||
9 | use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
||
10 | use Illuminate\Support\Facades\Storage; |
||
11 | |||
12 | /** |
||
13 | * Class Administrator. |
||
14 | * |
||
15 | * @property Role[] $roles |
||
16 | */ |
||
17 | class Administrator extends Model implements AuthenticatableContract |
||
18 | { |
||
19 | use Authenticatable, AdminBuilder, HasPermissions; |
||
20 | |||
21 | protected $fillable = ['username', 'password', 'name', 'avatar']; |
||
22 | |||
23 | /** |
||
24 | * Create a new Eloquent model instance. |
||
25 | * |
||
26 | * @param array $attributes |
||
27 | */ |
||
28 | View Code Duplication | public function __construct(array $attributes = []) |
|
0 ignored issues
–
show
|
|||
29 | { |
||
30 | $connection = config('admin.database.connection') ?: config('database.default'); |
||
31 | |||
32 | $this->setConnection($connection); |
||
33 | |||
34 | $this->setTable(config('admin.database.users_table')); |
||
35 | |||
36 | parent::__construct($attributes); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Get avatar attribute. |
||
41 | * |
||
42 | * @param string $avatar |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getAvatarAttribute($avatar) |
||
47 | { |
||
48 | $disk = config('admin.upload.disk'); |
||
49 | |||
50 | if ($avatar && array_key_exists($disk, config('filesystems.disks'))) { |
||
51 | return Storage::disk(config('admin.upload.disk'))->url($avatar); |
||
52 | } |
||
53 | |||
54 | return admin_asset('/vendor/laravel-admin/AdminLTE/dist/img/user2-160x160.jpg'); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * A user has and belongs to many roles. |
||
59 | * |
||
60 | * @return BelongsToMany |
||
61 | */ |
||
62 | View Code Duplication | public function roles() : BelongsToMany |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
63 | { |
||
64 | $pivotTable = config('admin.database.role_users_table'); |
||
65 | |||
66 | $relatedModel = config('admin.database.roles_model'); |
||
67 | |||
68 | return $this->belongsToMany($relatedModel, $pivotTable, 'user_id', 'role_id'); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * A User has and belongs to many permissions. |
||
73 | * |
||
74 | * @return BelongsToMany |
||
75 | */ |
||
76 | public function permissions() : BelongsToMany |
||
77 | { |
||
78 | $pivotTable = config('admin.database.user_permissions_table'); |
||
79 | |||
80 | $relatedModel = config('admin.database.permissions_model'); |
||
81 | |||
82 | return $this->belongsToMany($relatedModel, $pivotTable, 'user_id', 'permission_id'); |
||
83 | } |
||
84 | } |
||
85 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.