mercredi 26 octobre 2016

Laravel / Eloquent - Returning Related Table Columns At The Root Level and Not As Child Object Properties

When I use the with() method in the following fashion:

User::with('projects')->get();

I'll get a response that looks like:

Array(
    [0] => Array(
        [id] => 1
        [user_name] => big gulp
        [group_id] => 5
        [projects] => Array(
            [project_name] => new project
        )
    )
)

How do I get results which treats the columns related to the projects table as root level properties? I am looking for results that look like:

Array(
    [0] => Array(
        [id] => 1
        [user_name] => big gulp
        [group_id] => 5
        [project_name] => new project
    )
)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire