@@ -60,12 +60,12 @@ let's say the `Post` model has these fields
60
60
Schema::create('posts', function (Blueprint $table) {
61
61
$table->uuid('id')->primary(); // primary key
62
62
$table->foreignId('user_id')->constrained(); // required
63
- $table->foreignId('category ')->nullable(); // nullable
63
+ $table->foreignId('category_id ')->nullable(); // nullable
64
64
$table->uuid(); // required (but will be changed later) 👇
65
65
$table->ulid('ulid')->nullable(); // nullable (but will be changed later) 👇
66
66
$table->boolean('active')->default(false); // default
67
67
$table->string('title'); // required
68
- $table->json('description'); // nullable (but will be changed later) 👇
68
+ $table->json('description')->nullable() ; // nullable (but will be changed later) 👇
69
69
$table->string('slug')->nullable()->unique(); // nullable
70
70
$table->timestamps(); // nullable
71
71
$table->softDeletes(); // nullable
@@ -96,6 +96,112 @@ class Post extends Model
96
96
Post::requiredFields(); // returns ['user_id', 'ulid', 'title', 'description']
97
97
```
98
98
99
+ ### And more
100
+
101
+ We have the flexibility to get required fields with nullables, defaults, primary keys, and a mix of them or return all fields. You can use these methods with these results:
102
+
103
+ ``` php
104
+ // The default parameters, only required fields
105
+ Post::getRequiredFields(
106
+ $withNullables = false,
107
+ $withDefaults = false,
108
+ $withPrimaryKey = false
109
+ );
110
+ // or
111
+ Post::getRequiredFields();
112
+ // returns ['user_id', 'ulid', 'title', 'description']
113
+ ```
114
+
115
+ ``` php
116
+ // get required fields with nullables
117
+ Post::getRequiredFields(
118
+ $withNullables = true,
119
+ $withDefaults = false,
120
+ $withPrimaryKey = false
121
+ );
122
+ // or
123
+ Post::getRequiredFields(
124
+ $withNullables = true,
125
+ );
126
+ // or
127
+ Post::getRequiredFields(true);
128
+ // or
129
+ Post::getRequiredFieldsWithNullables();
130
+ // returns ['user_id', 'category_id', 'uuid', 'ulid', 'title', 'description', 'slug', 'created_at', 'updated_at', 'deleted_at']
131
+ ```
132
+
133
+ ``` php
134
+ // get required fields with defaults
135
+ Post::getRequiredFields(
136
+ $withNullables = false,
137
+ $withDefaults = true,
138
+ $withPrimaryKey = false
139
+ );
140
+ // or
141
+ Post::getRequiredFieldsWithDefaults();
142
+ // returns ['user_id', 'ulid', 'active', 'title', 'description']
143
+ ```
144
+
145
+ ``` php
146
+ // get required fields with primary key
147
+ Post::getRequiredFields(
148
+ $withNullables = false,
149
+ $withDefaults = false,
150
+ $withPrimaryKey = true
151
+ );
152
+ // or
153
+ Post::getRequiredFieldsWithPrimaryKey();
154
+ // returns ['id', 'user_id', 'ulid', 'title', 'description']
155
+ ```
156
+
157
+ ``` php
158
+ // get required fields with nullables and defaults
159
+ Post::getRequiredFields(
160
+ $withNullables = true,
161
+ $withDefaults = true,
162
+ $withPrimaryKey = false
163
+ );
164
+ // or
165
+ Post::getRequiredFieldsWithNullablesAndDefaults();
166
+ // returns ['user_id', 'category_id', 'uuid', 'ulid', 'active', 'title', 'description', 'slug', 'created_at', 'updated_at', 'deleted_at']
167
+ ```
168
+
169
+ ``` php
170
+ // get required fields with nullables and primary key
171
+ Post::getRequiredFields(
172
+ $withNullables = true,
173
+ $withDefaults = false,
174
+ $withPrimaryKey = true
175
+ );
176
+ // or
177
+ Post::getRequiredFieldsWithNullablesAndPrimaryKey();
178
+ // returns ['id', 'user_id', 'category_id', 'uuid', 'ulid', 'title', 'description', 'slug', 'created_at', 'updated_at', 'deleted_at']
179
+ ```
180
+
181
+ ``` php
182
+ // get required fields with defaults and primary key
183
+ Post::getRequiredFields(
184
+ $withNullables = false,
185
+ $withDefaults = true,
186
+ $withPrimaryKey = true
187
+ );
188
+ // or
189
+ Post::getRequiredFieldsWithDefaultsAndPrimaryKey();
190
+ // returns ['id', 'user_id', 'ulid', 'active', 'title', 'description']
191
+ ```
192
+
193
+ ``` php
194
+ // get required fields with defaults and primary key
195
+ Post::getRequiredFields(
196
+ $withNullables = true,
197
+ $withDefaults = true,
198
+ $withPrimaryKey = true
199
+ );
200
+ // or
201
+ Post::getAllFields();
202
+ // returns ['id', 'user_id', 'category_id', 'uuid', 'ulid', 'active', 'title', 'description', 'slug', 'created_at', 'updated_at', 'deleted_at']
203
+ ```
204
+
99
205
## Why?
100
206
101
207
### The problem
0 commit comments