Answer the question
In order to leave comments, you need to log in
The toArray method only returns the first level of nesting?
What am I doing wrong?
In the model:
class DocumentType extends Model
{
protected $fillable = [
'id',
'code',
'name',
'active',
];
public $childs;
print_r(DocumentType::getTree());
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Models\Docflow\DocumentType Object
(
[fillable:protected] => Array
(
[0] => id
[1] => code
[2] => name
[3] => active
)
[childs] => Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[7] => App\Models\Docflow\DocumentType Object .............
print_r(DocumentType::foo()->toArray());
Array
(
[0] => Array
(
[id] => 6
[parent_id] => 2
[code] =>
[name] => Приказ на переводе на другую должность
[active] => 1
)
Answer the question
In order to leave comments, you need to log in
Because what is serialized in $this->attributes and in $this->relations * . About the fact that you added some property to the class, Laravel does not know anything and whether you want to serialize it or not - too. In addition to the source code, it is also useful to read the documentation .
PS children, not childs.
* in fact, the logic is more complicated.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question