Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toArray() #6

Open
davidsteinsland opened this issue Jul 19, 2015 · 1 comment
Open

toArray() #6

davidsteinsland opened this issue Jul 19, 2015 · 1 comment

Comments

@davidsteinsland
Copy link

Would be nice if you would create a wrapper for toArray(), making the following output:

/* Entry belongsTo Channel, Entry hasMany Files */
$result = Entries::with('Channel', 'Files');
print_r($result->toArray());
[
    0 => [
        'id' => 1,
        'channel_id' => 1,
        'Channel' => [
            'id' => 1,
            'name' => 'My Chanel'
        ],
        'Files' => [
            0 => [
                'id' => 1,
                'entry_id' => 1,
                'name' => 'foo.jpg'
            ]
        ]
    ]
]

What I do currently:

$data = [];
$i = 0;
foreach ($result as $row) {
    $data[$i] = $row->toArray();
    $data[$i]['Channel'] = $row->channel->toArray();
    foreach ($row->files as $file) {
        $data[$i]['Files'][] = $file->toArray();
    }
    $i++;
}
@erisrayanesh
Copy link

Same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants