Completed
Push — master ( a91b57...4fcfbd )
by Jan
06:59
created

User::usergroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * User module model
4
 * 
5
 * Model for module User
6
 * 
7
 * @category Model
8
 * @subpackage Admin
9
 * @package Olapus
10
 * @author Jan Drda <[email protected]>
11
 * @copyright Jan Drda
12
 * @license https://opensource.org/licenses/MIT MIT
13
 */
14
15
namespace App;
16
17
use Illuminate\Auth\Authenticatable;
18
use Illuminate\Database\Eloquent\Model;
19
use Illuminate\Auth\Passwords\CanResetPassword;
20
use Illuminate\Foundation\Auth\Access\Authorizable;
21
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
22
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
23
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
24
use Illuminate\Database\Eloquent\SoftDeletes;
25
26
class User extends Model implements AuthenticatableContract,
27
                                    AuthorizableContract,
28
                                    CanResetPasswordContract
29
{
30
    use Authenticatable, Authorizable, CanResetPassword, SoftDeletes, AdminModelTrait;
31
32
    /**
33
     * The database table used by the model.
34
     *
35
     * @var string
36
     */
37
    protected $table = 'users';
38
    
39
    /**
40
     * The attributes that should be mutated to dates.
41
     *
42
     * @var array
43
     */
44
    protected $dates = ['created_at', 'updated_at', 'deleted_at'];
45
46
    /**
47
     * The attributes that are mass assignable.
48
     *
49
     * @var array
50
     */
51
    protected $fillable = ['name', 'email', 'password', 'age', 'blacklisted', 'ip', 'activation_code', 'active',
52
    'fname', 'sname', 'bno', 'city', 'citypart', 'street', 'hno', 'zip', 'registration_data', 'phone'];
53
54
    /**
55
     * The attributes excluded from the model's JSON form.
56
     *
57
     * @var array
58
     */
59
    protected $hidden = ['password', 'remember_token'];
60
    
61
    /**
62
     * Columns to exclude from index
63
     * 
64
     * @var array 
65
     */
66
    protected $excludedFromIndex = ['password'];
67
    
68
    /**
69
     * Fields to search in fulltext mode
70
     * 
71
     * @var array
72
     */
73
    protected $fulltextFields = [
74
        'id',
75
        'name' => [
76
            'operator' => 'LIKE',
77
            'prefix' => '%',
78
            'sufix' => '%'
79
        ],
80
        'email' => [
81
            'operator' => 'LIKE',
82
            'prefix' => '%',
83
            'sufix' => '%'
84
        ],
85
    ];
86
    
87
    /**
88
     * Default order by
89
     * 
90
     * @var array
91
     */
92
    protected $defaultOrderBy = [
93
      'id' => 'desc'  
94
    ];
95
    
96
    /**
97
     * Articles link
98
     * 
99
     * @return object
100
     */
101
    public function articles(){
102
        
103
        return $this->hasMany('App\Article', 'user_id');
104
    }
105
106
    /**
107
     * User group link
108
     *
109
     * @return object
110
     */
111
    public function usergroups(){
112
113
        return $this->belongsTo('App\Usergroup', 'usergroup_id');
114
    }
115
    
116
    /**
117
     * Process relationships
118
     * 
119
     * @param query $query
120
     * @return query
121
     */
122
    public function scopeRelationships($query){
123
        
124
        return $query->with('usergroups');
125
    }
126
}
127