File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,31 @@ public function toArray()
222222 return array_merge ($ this ->attributesToArray (), $ this ->variablesToArray ());
223223 }
224224
225+ /**
226+ * Convert the model's attributes to an array.
227+ *
228+ * @return array
229+ */
230+ public function attributesToArray ()
231+ {
232+ // If an attribute is a date, we will cast it to a string after converting it
233+ // to a DateTime / Carbon instance. This is so we will get some consistent
234+ // formatting while accessing attributes vs. arraying / JSONing a model.
235+ $ attributes = $ this ->addDateAttributesToArray (
236+ $ attributes = $ this ->getArrayableAttributes ()
237+ );
238+
239+
240+ // Here we will grab all of the appended, calculated attributes to this model
241+ // as these attributes are not really in the attributes array, but are run
242+ // when we need to array or JSON the model for convenience to the coder.
243+ foreach ($ this ->getArrayableAppends () as $ key ) {
244+ $ attributes [$ key ] = $ this ->mutateAttributeForArray ($ key , null );
245+ }
246+
247+ return $ attributes ;
248+ }
249+
225250 /**
226251 * Convert the object to its JSON representation.
227252 *
You can’t perform that action at this time.
0 commit comments