Almost, we set the fields visible or hidden by two properties from eloquent, but sometimes we need to show specific fields temporarily, how do we do?


From Laravel news Instagram, I saw useful methods from underlying eloquent.

For example, we have hidden two fields, address and phone_number, but now we need to show them.

makeVisible($attributes)

The makeVisible method makes visible attributes that are typically ‘hidden’ on each model in the collection:

$users = $users->makeVisible(['address', 'phone_number']);

On the other hand, address and phone_number are visible, we need hiding them for now.

makeHidden($attributes)

The makeHidden method hides attributes that are typically ‘visible’ on each model in the collection:

$users = $users->makeHidden(['address', 'phone_number']);

It’s pretty useful.