1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Repositories; |
4
|
|
|
|
5
|
|
|
use Slides\Saml2\Models\Tenant; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class TenantRepository |
9
|
|
|
* |
10
|
|
|
* @package Slides\Saml2\Repositories |
11
|
|
|
*/ |
12
|
|
|
class TenantRepository |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Create a new query. |
16
|
|
|
* |
17
|
|
|
* @param bool $withTrashed Whether need to include safely deleted records. |
18
|
|
|
* |
19
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
20
|
|
|
*/ |
21
|
|
|
public function query(bool $withTrashed = false) |
22
|
|
|
{ |
23
|
|
|
$query = Tenant::query(); |
24
|
|
|
|
25
|
|
|
if($withTrashed) { |
26
|
|
|
$query->withTrashed(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
return $query; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Find all tenants. |
34
|
|
|
* |
35
|
|
|
* @param bool $withTrashed Whether need to include safely deleted records. |
36
|
|
|
* |
37
|
|
|
* @return Tenant[]|\Illuminate\Database\Eloquent\Collection |
38
|
|
|
*/ |
39
|
|
|
public function all(bool $withTrashed = true) |
40
|
|
|
{ |
41
|
|
|
return $this->query($withTrashed)->get(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Find a tenant by any identifier. |
46
|
|
|
* |
47
|
|
|
* @param int|string $key ID, key or UUID |
48
|
|
|
* @param bool $withTrashed Whether need to include safely deleted records. |
49
|
|
|
* |
50
|
|
|
* @return Tenant[]|\Illuminate\Database\Eloquent\Collection |
51
|
|
|
*/ |
52
|
|
|
public function findByAnyIdentifier($key, bool $withTrashed = true) |
53
|
|
|
{ |
54
|
|
|
return $this->query($withTrashed) |
55
|
|
|
->where('id', $key) |
56
|
|
|
->orWhere('key', $key) |
57
|
|
|
->orWhere('uuid', $key) |
58
|
|
|
->get(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Find a tenant by the key. |
63
|
|
|
* |
64
|
|
|
* @param string $key |
65
|
|
|
* @param bool $withTrashed |
66
|
|
|
* |
67
|
|
|
* @return Tenant|\Illuminate\Database\Eloquent\Model|null |
68
|
|
|
*/ |
69
|
|
|
public function findByKey(string $key, bool $withTrashed = true) |
70
|
|
|
{ |
71
|
|
|
return $this->query($withTrashed) |
72
|
|
|
->where('key', $key) |
73
|
|
|
->first(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Find a tenant by ID. |
78
|
|
|
* |
79
|
|
|
* @param int $id |
80
|
|
|
* @param bool $withTrashed |
81
|
|
|
* |
82
|
|
|
* @return Tenant|\Illuminate\Database\Eloquent\Model|null |
83
|
|
|
*/ |
84
|
|
|
public function findById(int $id, bool $withTrashed = true) |
85
|
|
|
{ |
86
|
|
|
return $this->query($withTrashed) |
87
|
|
|
->where('id', $id) |
88
|
|
|
->first(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Find a tenant by UUID. |
93
|
|
|
* |
94
|
|
|
* @param int $uuid |
95
|
|
|
* @param bool $withTrashed |
96
|
|
|
* |
97
|
|
|
* @return Tenant|\Illuminate\Database\Eloquent\Model|null |
98
|
|
|
*/ |
99
|
|
|
public function findByUUID(string $uuid, bool $withTrashed = true) |
100
|
|
|
{ |
101
|
|
|
return $this->query($withTrashed) |
102
|
|
|
->where('uuid', $uuid) |
103
|
|
|
->first(); |
104
|
|
|
} |
105
|
|
|
} |