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

ThePoet444's avatar

Adding permissions to roles via checkbox grid help

So I was pondering the easiest way to list all the roles I have and all the permissions and try to assign them. I don't plan on having many roles but permissions I can see a few. I stumbled across a layout that I loved, but it was in rails (see: http://stackoverflow.com/questions/15345310/how-to-create-a-checkbox-grid-using-a-has-many-through-association ). I would love to know how to do this is laravel though. I figure I can return an eloquent collection and filter the headings as roles... but after that I'm lost and confused. I can't seem to find the right keywords to get me started either. Can someone either point me to some code examples that will do this type of layout and operation, or at the very least give me a list of keywords to search for so I can figure it out. I'm sure the answer is painfully obvious and staring me in the face, but being a novice programmer I'm just not seeing it. Thanks in advance!

0 likes
3 replies
rieves's avatar
rieves
Best Answer
Level 4

It's looping through each permission. Each permission is then looping through each role (which lines it up with the headings) and makes a checkbox for that role. The checkbox name has an array which includes the role id and then value has the permission id in it. Then it checks if that role has that permission and ticks it if it has.

I hope that helps you with the layout.

1 like
ThePoet444's avatar

I'll have to see if I can code that up so I can try and understand it a bit more, but I think I have the basic understanding of it. Having it explained that way makes a little more sense than trying to figure out ruby code (Of which I know nothing). Thank you. :)

Please or to participate in this conversation.