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!
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.
Thanks for the feedback. Glad you figured something out! Make sure to mark your own answer as the resolution for future lurkers too.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community