Reputation: 2000
I am using laravel 5.5 and bouncer package for role system which here is link to it
https://github.com/JosephSilber/bouncer
So now every thing is fine until I want some user to see some menus and some wont and menus are static and not dynamically so I want to make a table with some check boxes like the below example
<table>
<tr>
<td>menu1</td>
<td>menu2</td>
<td>menu3</td>
<td>menu4</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td><input type="checkbox"></td>
<td><input type="checkbox"></td>
<td><input type="checkbox"></td>
</tr>
</table>
And here its simple I wanted to check if the input for menu2 for example is checked so it adds some @can
to view and if not remove it I have doubt that I need to save it in database or not I would be happy for some help
Upvotes: 0
Views: 115
Reputation: 171
<tr>
<td><input type="checkbox" name="roles[]"></td>
<td><input type="checkbox" name="roles[]"></td>
<td><input type="checkbox" name="roles[]"></td>
<td><input type="checkbox" name="roles[]"></td>
</tr>
you should have roles
table which have all roles you need to control it
then make pivot
table
user_id role_id
then in user
model create relation called roles
(many to many)
then in controller you can get it
$roles = request('roles');
with using roles
relation you can make this
$user->roles()->sync($roles);
Upvotes: 1
Reputation: 108
<table>
<tr>
<td>menu1</td>
<td>menu2</td>
<td>menu3</td>
<td>menu4</td>
</tr>
<tr>
<td><input type="checkbox" id="menu1" name="menu1"></td>
<td><input type="checkbox" id="menu2" name="menu2"></td>
<td><input type="checkbox" id="menu3" name="menu3"></td>
<td><input type="checkbox" id="menu4" name="menu4"></td>
</tr>
</table>
You have to add id and name tag to the checkboxes, and then you can see when its posted if data is recieved. If recieved its checked else no data is recieved.
Like this:
$menu1 = $_POST['menu1'];
$menu2 = $_POST['menu2'];
$menu3 = $_POST['menu3'];
$menu4 = $_POST['menu4'];
Upvotes: 0