Framework: Eloquent Collection's makeVisible method only works when using the 'hidden' property

Created on 28 Mar 2016  路  5Comments  路  Source: laravel/framework

I came to an unexpected result when using makeVisible method and not making the attributes I passed visible, so I saw that the reason was that the method will only make visible the fields if them are in the 'hidden' property.

Model.php

    protected $visible = ['remaining', 'restored_at'];
    // id not returned
    $model->all()->makeVisible(['id'])->toArray();

Instead having Model.php

    protected $hidden = ['id'];
    // id returned
    $model->all()->makeVisible(['id'])->toArray();

The easy workaround would be using hidden property but I'm making a package and I need to get a full properties toArray() no matter which property the user uses.

Is this the expected behaviour?

bug

Most helpful comment

Ping @taylorotwell.

All 5 comments

Ping @taylorotwell.

I was facing the same problem. I ended using the hidden property.

In my opinion makeVisible should... make visible the passed attributes, so yes, weird behaviour.

....I've run into this bug too...
debug for a total afternoon!

thks @marcmascarell

Fix already merged.

Will be available in the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

JamborJan picture JamborJan  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

RomainSauvaire picture RomainSauvaire  路  3Comments