Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Eloquent\Concerns;
4
 
5
trait HidesAttributes
6
{
7
    /**
8
     * The attributes that should be hidden for serialization.
9
     *
10
     * @var array<string>
11
     */
12
    protected $hidden = [];
13
 
14
    /**
15
     * The attributes that should be visible in serialization.
16
     *
17
     * @var array<string>
18
     */
19
    protected $visible = [];
20
 
21
    /**
22
     * Get the hidden attributes for the model.
23
     *
24
     * @return array<string>
25
     */
26
    public function getHidden()
27
    {
28
        return $this->hidden;
29
    }
30
 
31
    /**
32
     * Set the hidden attributes for the model.
33
     *
34
     * @param  array<string>  $hidden
35
     * @return $this
36
     */
37
    public function setHidden(array $hidden)
38
    {
39
        $this->hidden = $hidden;
40
 
41
        return $this;
42
    }
43
 
44
    /**
45
     * Get the visible attributes for the model.
46
     *
47
     * @return array<string>
48
     */
49
    public function getVisible()
50
    {
51
        return $this->visible;
52
    }
53
 
54
    /**
55
     * Set the visible attributes for the model.
56
     *
57
     * @param  array<string>  $visible
58
     * @return $this
59
     */
60
    public function setVisible(array $visible)
61
    {
62
        $this->visible = $visible;
63
 
64
        return $this;
65
    }
66
 
67
    /**
68
     * Make the given, typically hidden, attributes visible.
69
     *
70
     * @param  array<string>|string|null  $attributes
71
     * @return $this
72
     */
73
    public function makeVisible($attributes)
74
    {
75
        $attributes = is_array($attributes) ? $attributes : func_get_args();
76
 
77
        $this->hidden = array_diff($this->hidden, $attributes);
78
 
79
        if (! empty($this->visible)) {
80
            $this->visible = array_merge($this->visible, $attributes);
81
        }
82
 
83
        return $this;
84
    }
85
 
86
    /**
87
     * Make the given, typically hidden, attributes visible if the given truth test passes.
88
     *
89
     * @param  bool|\Closure  $condition
90
     * @param  array<string>|string|null  $attributes
91
     * @return $this
92
     */
93
    public function makeVisibleIf($condition, $attributes)
94
    {
95
        return value($condition, $this) ? $this->makeVisible($attributes) : $this;
96
    }
97
 
98
    /**
99
     * Make the given, typically visible, attributes hidden.
100
     *
101
     * @param  array<string>|string|null  $attributes
102
     * @return $this
103
     */
104
    public function makeHidden($attributes)
105
    {
106
        $this->hidden = array_merge(
107
            $this->hidden, is_array($attributes) ? $attributes : func_get_args()
108
        );
109
 
110
        return $this;
111
    }
112
 
113
    /**
114
     * Make the given, typically visible, attributes hidden if the given truth test passes.
115
     *
116
     * @param  bool|\Closure  $condition
117
     * @param  array<string>|string|null  $attributes
118
     * @return $this
119
     */
120
    public function makeHiddenIf($condition, $attributes)
121
    {
122
        return value($condition, $this) ? $this->makeHidden($attributes) : $this;
123
    }
124
}