File tree 3 files changed +33
-3
lines changed
3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ class Field
46
46
*/
47
47
protected $ nullable = false ;
48
48
49
+ /**
50
+ * Indicates if the field can be omitted on create.
51
+ *
52
+ * @var bool
53
+ */
54
+ protected $ nullableOnCreate = false ;
55
+
49
56
/**
50
57
* @var bool
51
58
*/
@@ -276,6 +283,29 @@ public function isNullable(): bool
276
283
return $ this ->nullable ;
277
284
}
278
285
286
+ /**
287
+ * Set if the field can be omitted on create.
288
+ *
289
+ * @param bool $nullable
290
+ * @return \Bakery\Fields\Field
291
+ */
292
+ public function nullableOnCreate (bool $ nullable = true ): self
293
+ {
294
+ $ this ->nullableOnCreate = $ nullable ;
295
+
296
+ return $ this ;
297
+ }
298
+
299
+ /**
300
+ * Determine if the field can be omitted on create.
301
+ *
302
+ * @return bool
303
+ */
304
+ public function isNullableOnCreate ()
305
+ {
306
+ return $ this ->nullableOnCreate ;
307
+ }
308
+
279
309
/**
280
310
* Set if the field has nullable items.
281
311
*
Original file line number Diff line number Diff line change @@ -49,8 +49,8 @@ protected function getFillableFields(): Collection
49
49
$ fields = parent ::getFillableFields ();
50
50
$ defaults = $ this ->model ->getAttributes ();
51
51
52
- return $ fields ->map (function (Field $ field, $ key ) use ($ defaults ) {
53
- if (in_array ( $ key , array_keys ( $ defaults ) )) {
52
+ return $ fields ->map (function (Field $ field ) use ($ defaults ) {
53
+ if ($ field -> isNullableOnCreate ( )) {
54
54
return $ field ->nullable ();
55
55
}
56
56
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public function fields(): array
16
16
return [
17
17
'name ' => Field::string ()->searchable (),
18
18
'email ' => Field::string ()->unique ()->searchable (),
19
- 'type ' => Field::string ()->canStoreWhen ('setType ' ),
19
+ 'type ' => Field::string ()->nullableOnCreate ()-> canStoreWhen ('setType ' ),
20
20
'password ' => Field::string ()->canSeeWhen ('readPassword ' ),
21
21
'secret_information ' => Field::string ()
22
22
->canSee (function (?Authenticatable $ user , User $ source ) {
You can’t perform that action at this time.
0 commit comments