Passed
Push — main ( 1f5895...cce870 )
by Thierry
08:23
created

Tontine::invites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Siak\Tontine\Model;
4
5
use Database\Factories\TontineFactory;
6
use Illuminate\Database\Eloquent\Casts\Attribute;
7
use Illuminate\Database\Eloquent\Factories\Factory;
8
use Illuminate\Database\Eloquent\Factories\HasFactory;
9
10
class Tontine extends Base
11
{
12
    use HasFactory;
13
    use Traits\HasProperty;
0 ignored issues
show
introduced by
The trait Siak\Tontine\Model\Traits\HasProperty requires some properties which are not provided by Siak\Tontine\Model\Tontine: $property, $content
Loading history...
14
15
    /**
16
     * True if the tontine is accessed as guest.
17
     *
18
     * @var bool
19
     */
20
    public $isGuest = false;
21
22
    /**
23
     * The attributes that are mass assignable.
24
     *
25
     * @var array
26
     */
27
    protected $fillable = [
28
        'type',
29
        'name',
30
        'shortname',
31
        'biography',
32
        'email',
33
        'phone',
34
        'address',
35
        'city',
36
        'website',
37
        'country_code',
38
        'currency_code',
39
    ];
40
41
    /**
42
     * The model's default values for attributes.
43
     *
44
     * @var array
45
     */
46
    protected $attributes = [
47
        'type' => 'x',
48
    ];
49
50
    /**
51
     * @return Attribute
52
     */
53
    protected function locale(): Attribute
54
    {
55
        return Attribute::make(
56
            get: fn() => $this->user->locale,
0 ignored issues
show
Bug introduced by
The property locale does not seem to exist on Siak\Tontine\Model\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
57
        );
58
    }
59
60
    /**
61
     * Create a new factory instance for the model.
62
     *
63
     * @return Factory
64
     */
65
    protected static function newFactory()
66
    {
67
        return TontineFactory::new();
68
    }
69
70
    public function user()
71
    {
72
        return $this->belongsTo(User::class);
73
    }
74
75
    public function members()
76
    {
77
        return $this->hasMany(Member::class)->orderBy('name', 'asc');
78
    }
79
80
    public function rounds()
81
    {
82
        return $this->hasMany(Round::class)->orderBy('rounds.id', 'desc');
83
    }
84
85
    public function sessions()
86
    {
87
        return $this->hasManyThrough(Session::class, Round::class)
88
            ->select('sessions.*');
89
    }
90
91
    public function funds()
92
    {
93
        return $this->hasMany(Fund::class);
94
    }
95
96
    public function charges()
97
    {
98
        return $this->hasMany(Charge::class);
99
    }
100
101
    public function categories()
102
    {
103
        return $this->hasMany(Category::class);
104
    }
105
106
    public function invites()
107
    {
108
        return $this->belongsToMany(GuestInvite::class,
109
            'guest_tontine', 'tontine_id', 'invite_id')
110
            ->as('permission')
111
            ->withPivot('access')
112
            ->using(GuestTontine::class);
113
    }
114
}
115