Completed
Push — master ( d44ef5...c7e879 )
by Fèvre
12s
created

DiscussUser::conversation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Eloquence\Behaviours\CountCache\Countable;
5
use Illuminate\Support\Facades\Auth;
6
7
class DiscussUser extends Model
8
{
9
    use Countable;
10
11
    /**
12
     * The attributes that are mass assignable.
13
     *
14
     * @var array
15
     */
16
    protected $fillable = [
17
        'user_id',
18
        'conversation_id'
19
    ];
20
21
    /**
22
     * The "booting" method of the model.
23
     *
24
     * @return void
25
     */
26
    protected static function boot()
27
    {
28
        parent::boot();
29
30
        // Set the user id to the new user before saving it.
31
        static::creating(function ($model) {
32
            $model->user_id = Auth::id();
33
        });
34
    }
35
36
    /**
37
     * Return the count cache configuration.
38
     *
39
     * @return array
40
     */
41
    public function countCaches(): array
42
    {
43
        return [
44
            'user_count' => [DiscussConversation::class, 'conversation_id', 'id']
45
        ];
46
    }
47
48
    /**
49
     * Get the user that owns the user.
50
     *
51
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
52
     */
53
    public function user()
54
    {
55
        return $this->belongsTo(User::class);
56
    }
57
58
    /**
59
     * Get the conversation that owns the user.
60
     *
61
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
62
     */
63
    public function conversation()
64
    {
65
        return $this->belongsTo(DiscussConversation::class);
66
    }
67
}
68