|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
|
|
8
|
|
|
class ThingSettings extends Model |
|
9
|
|
|
{ |
|
10
|
|
|
public function thing() |
|
11
|
|
|
{ |
|
12
|
|
|
return $this->belongsTo(Thing::class); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function library() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->belongsTo(Library::class); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The attributes that are mass assignable. |
|
22
|
|
|
* |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $fillable = ['thing_id', 'library_id']; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The attributes that should be cast to native types. |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $casts = [ |
|
33
|
|
|
'data' => 'array', |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The accessors to append to the model's array form. |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $appends = ['loans_without_barcode', 'reminders', 'loan_time']; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The attributes that should be visible in arrays. |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $visible = ['loans_without_barcode', 'reminders', 'loan_time']; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Helper method to update setting. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function setValue(string $key, $value) |
|
54
|
|
|
{ |
|
55
|
|
|
$data = $this->data; |
|
56
|
|
|
Arr::set($data, $key, $value); |
|
57
|
|
|
$this->data = $data; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the loans_without_barcode value. |
|
62
|
|
|
* |
|
63
|
|
|
* @param boolean $value |
|
64
|
|
|
* @return boolean |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getLoansWithoutBarcodeAttribute() |
|
67
|
|
|
{ |
|
68
|
|
|
return Arr::get($this->data, 'loans_without_barcode', false); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set the loans_without_barcode value. |
|
73
|
|
|
* |
|
74
|
|
|
* @param boolean $value |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setLoansWithoutBarcodeAttribute(bool $value) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->setValue('loans_without_barcode', (bool) $value); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the reminders value. |
|
83
|
|
|
* |
|
84
|
|
|
* @return boolean |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getRemindersAttribute() |
|
87
|
|
|
{ |
|
88
|
|
|
return Arr::get($this->data, 'reminders', true); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set the reminders value. |
|
93
|
|
|
* |
|
94
|
|
|
* @param boolean $value |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setRemindersAttribute(bool $value) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->setValue('reminders', (bool) $value); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the reminders value. |
|
103
|
|
|
* |
|
104
|
|
|
* @return boolean |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getLoanTimeAttribute() |
|
107
|
|
|
{ |
|
108
|
|
|
return Arr::get($this->data, 'loan_time', 1); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set the loan_time value. |
|
113
|
|
|
* |
|
114
|
|
|
* @param boolean $value |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setLoanTimeAttribute(int $value) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->setValue('loan_time', (int) $value); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.