UserPreferences::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Class UserPreferences.
9
 */
10
class UserPreferences extends Model
11
{
12
    /**
13
     * Disable Timestamps.
14
     *
15
     * @var bool
16
     */
17
    public $timestamps = false;
18
19
    /**
20
     * The table associated with the model.
21
     *
22
     * @var string
23
     */
24
    protected $table = 'chocolatey_users_preferences';
25
26
    /**
27
     * Primary Key of the Table.
28
     *
29
     * @var string
30
     */
31
    protected $primaryKey = 'user_id';
32
33
    /**
34
     * The attributes excluded from the model's JSON form.
35
     *
36
     * @var array
37
     */
38
    protected $hidden = ['user_id'];
39
40
    /**
41
     * The attributes that are mass assignable.
42
     *
43
     * @var array
44
     */
45
    protected $fillable = ['emailFriendRequestNotificationEnabled', 'emailGiftNotificationEnabled', 'emailGroupNotificationEnabled', 'emailMiniMailNotificationEnabled',
46
        'emailNewsletterEnabled', 'emailRoomMessageNotificationEnabled', 'friendCanFollow', 'friendRequestEnabled', 'offlineMessagingEnabled', 'onlineStatusVisible', 'profileVisible', ];
47
48
    /**
49
     * Store an User Preference set on the Database.
50
     *
51
     * @param int $userId
52
     *
53
     * @return UserPreferences
54
     */
55
    public function store(int $userId): UserPreferences
56
    {
57
        $this->attributes['user_id'] = $userId;
58
        $this->timestamps = false;
59
60
        $this->save();
61
62
        return $this;
63
    }
64
}
65