Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shez1983's avatar
Level 23

hiding data in livewire? backend/Admin Vs customer, dynamically hiding?

so I am testing livewire and if i have a model and in component I do Model::all(); it will pass all the data to the view.

I can use protected $hidden = ['property']; in the model and this does HIDE the properties. BUT this is not very dynamic, for example in a customer facing if i do Model::all() vs admin/backend where i do Model::all(), i may not need to show property to customer but would need to show it to admin?

Any suggestions?

0 likes
2 replies
Snapey's avatar

Load your data in the render method and pass it to the view.

Your server side rendered blade template will not show any data that you have not used in the blade file.

If the user is an admin then you can use @if etc to show content to admins only.

Just the same as with a non-livewire view

1 like
shez1983's avatar
Level 23

@Snapey thanks, i did try that and to me that seems a bit messy as i need to loop over the query results/collection and remove the data VS say using API Resources or maybe do a Query and use the columns in the get() method but then i'll have to do that everywhere.. :/

maybe the render method can use a 'an external class method' to do this so i dont have to repeat the logic. everywhere i need it ?

Please or to participate in this conversation.