Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I think the answer may be in how the all() function is called

/**
 * Get all of the models from the database.
 *
 * @param array $columns
 * @return \Illuminate\Database\Eloquent\Collection|static[]
 */
public static function all($columns = array('*'))
{
    $instance = new static;
    return $instance->newQuery()->get($columns);
}

setHidden() will set the $hidden attribute for the current instance, but all() will call a new static instance to grab from the database. Try toArray(), which should work with the $obj itself. You could also try to save the object before calling all().

Let me know if this helps!

Last updated 2 years ago.
0

Thanks for thinking with me ;-)

toArray didn't do it for me..

Ended up choosing the following: (altered from an old forum post: http://forumsarchive.laravel.io/viewtopic.php?id=8268)

$results = \Company::all()->each(function($row)
{
    $row->setHidden(['profile', 'description']);
});
return $results;

Which yielded the result I was looking for, at the expense of a loop over the results. but since I probably have one or two other functions to parse the results thru, this will do quite nicely.

Last updated 2 years ago.
0

Thanks for the feedback. Glad you figured something out! Make sure to mark your own answer as the resolution for future lurkers too.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ReLexEd relexed Joined 19 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.