@@ -53,24 +53,25 @@ public function create($option, array $data)
5353 'env_variable ' => 'required|regex:/^[\w]{1,255}$/ ' ,
5454 'default_value ' => 'string ' ,
5555 'options ' => 'sometimes|required|array ' ,
56- 'rules ' => 'bail|required|string|min:1 ' ,
56+ 'rules ' => 'bail|required|string ' ,
5757 ]);
5858
5959 // Ensure the default value is allowed by the rules provided.
60- $ rules = (isset ($ data ['rules ' ])) ? $ data ['rules ' ] : $ variable ->rules ;
61- $ validator ->sometimes ('default_value ' , $ rules , function ($ input ) {
60+ $ validator ->sometimes ('default_value ' , $ data ['rules ' ] ?? null , function ($ input ) {
6261 return $ input ->default_value ;
6362 });
6463
6564 if ($ validator ->fails ()) {
6665 throw new DisplayValidationException (json_encode ($ validator ->errors ()));
6766 }
6867
69- if (isset ($ data ['env_variable ' ])) {
70- $ search = ServiceVariable::where ('env_variable ' , $ data ['env_variable ' ])->where ('option_id ' , $ option ->id );
71- if ($ search ->first ()) {
72- throw new DisplayException ('The envionment variable name assigned to this variable must be unique for this service option. ' );
73- }
68+ if (in_array ($ data ['env_variable ' ], ServiceVariable::reservedNames ())) {
69+ throw new DisplayException ('The environment variable name provided is a reserved keyword for the daemon. ' );
70+ }
71+
72+ $ search = ServiceVariable::where ('env_variable ' , $ data ['env_variable ' ])->where ('option_id ' , $ option ->id );
73+ if ($ search ->first ()) {
74+ throw new DisplayException ('The envionment variable name assigned to this variable must be unique for this service option. ' );
7475 }
7576
7677 if (! isset ($ data ['options ' ]) || ! is_array ($ data ['options ' ])) {
@@ -141,6 +142,10 @@ public function update($id, array $data)
141142 }
142143
143144 if (isset ($ data ['env_variable ' ])) {
145+ if (in_array ($ data ['env_variable ' ], ServiceVariable::reservedNames ())) {
146+ throw new DisplayException ('The environment variable name provided is a reserved keyword for the daemon. ' );
147+ }
148+
144149 $ search = ServiceVariable::where ('env_variable ' , $ data ['env_variable ' ])
145150 ->where ('option_id ' , $ variable ->option_id )
146151 ->where ('id ' , '!= ' , $ variable ->id );
0 commit comments