Fix to_array() in eloquent model.
This commit is contained in:
@@ -607,7 +607,7 @@ abstract class Model {
|
|||||||
// If the relationship is not a "to-many" relationship, we can just
|
// If the relationship is not a "to-many" relationship, we can just
|
||||||
// to_array the related model and add it as an attribute to the
|
// to_array the related model and add it as an attribute to the
|
||||||
// array of existing regular attributes we gathered.
|
// array of existing regular attributes we gathered.
|
||||||
if ( ! is_array($models))
|
if ($models instanceof Model)
|
||||||
{
|
{
|
||||||
$attributes[$name] = $models->to_array();
|
$attributes[$name] = $models->to_array();
|
||||||
}
|
}
|
||||||
@@ -615,13 +615,17 @@ abstract class Model {
|
|||||||
// If the relationship is a "to-many" relationship we need to spin
|
// If the relationship is a "to-many" relationship we need to spin
|
||||||
// through each of the related models and add each one with the
|
// through each of the related models and add each one with the
|
||||||
// to_array method, keying them both by name and ID.
|
// to_array method, keying them both by name and ID.
|
||||||
else
|
elseif (is_array($models))
|
||||||
{
|
{
|
||||||
foreach ($models as $id => $model)
|
foreach ($models as $id => $model)
|
||||||
{
|
{
|
||||||
$attributes[$name][$id] = $model->to_array();
|
$attributes[$name][$id] = $model->to_array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif (is_null($models))
|
||||||
|
{
|
||||||
|
$attributes[$name] = $models;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $attributes;
|
return $attributes;
|
||||||
|
|||||||
Reference in New Issue
Block a user