Issues (5)

src/Tenancy/Tenant.php (1 issue)

1
<?php
2
3
namespace CmdrSharp\NetBox\Tenancy;
4
5
use CmdrSharp\NetBox\NetBox;
6
use CmdrSharp\NetBox\Traits\HandlesNetBoxResults;
7
use CmdrSharp\NetBox\Traits\RequiresSlugs;
8
9
class Tenant extends NetBox
10
{
11
    use HandlesNetBoxResults,
0 ignored issues
show
The trait CmdrSharp\NetBox\Traits\HandlesNetBoxResults requires some properties which are not provided by CmdrSharp\NetBox\Tenancy\Tenant: $count, $results, $id
Loading history...
12
        RequiresSlugs;
13
14
    /** @var string */
15
    const API_PATH = parent::API_PATH . 'tenancy/tenants/';
16
17
    /** @var array|string[] */
18
    protected array $fillable = [
19
        'name',
20
        'slug',
21
        'group',
22
        'description',
23
        'comments',
24
    ];
25
26
    /**
27
     * @param string $name
28
     * @return Tenant
29
     */
30
    public function setName(string $name): Tenant
31
    {
32
        $this->setAttribute('name', $name);
33
34
        return $this;
35
    }
36
37
    /**
38
     * @param string $slug
39
     * @param bool $slugify
40
     * @return $this
41
     */
42
    public function setSlug(string $slug, bool $slugify = true): Tenant
43
    {
44
        if ($slugify) {
45
            $slug = $this->slugify($slug);
46
        }
47
48
        $this->setAttribute('slug', $slug);
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param int $id
55
     * @return Tenant
56
     */
57
    public function setGroup(int $id): Tenant
58
    {
59
        $this->setAttribute('group', $id);
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param string $name
66
     * @return $this
67
     */
68
    public function setGroupByName(string $name): Tenant
69
    {
70
        $groupQuery = TenantGroup::whereName($name);
71
        $group = $this->getOnlyResult($groupQuery);
72
73
        $this->setAttribute('group', $group->id);
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param string $description
80
     * @return $this
81
     */
82
    public function setDescription(string $description): Tenant
83
    {
84
        $this->setAttribute('description', $description);
85
86
        return $this;
87
    }
88
89
    /**
90
     * @param string $comments
91
     * @return $this
92
     */
93
    public function setComments(string $comments): Tenant
94
    {
95
        $this->setAttribute('comments', $comments);
96
97
        return $this;
98
    }
99
}
100