Back

implement user-role -permission system


hi i have two problem that i don't know how to solve this situation: i have user role permission table and i use zizaco

<tbody>
	@foreach($role as $roles)
		<tr>
			<td>{{ Form::label('roles', $roles->display_name) }}</td>
			<td>{{ Form::checkbox('roles[]', $roles->id) }}</td>
			foreach ($permission as $permissions)
				<td>
				{{ Form::checkbox('$permissions[]',$permissions->id) }} -->this section does not work correctly all checkbox are uncheck while user have this role and this permission
				</td>
			@endforeach
		</tr>
	@endforeach
</tbody>

and in my usrmngmntController we have:

public function update($id)
     {
          $user=User::find($id);
          $user->roles()->sync(Input::get('roles',[]));
           --> in this place i do not know how to sync like above form role->permission table
      }

if you can help me it's appreciated thanks

noxify replied 6 months ago

Hi,

your checkbox is always unchecked, because the third parameter is missing. See: https://laravelcollective.com/docs/5.3/html#checkboxes-and-radio-buttons

asadi20 replied 6 months ago

noxify said:

Hi,

your checkbox is always unchecked, because the third parameter is missing. See: https://laravelcollective.com/docs/5.3/html#checkboxes-and-radio-buttons

thanks for your answer but when i use true option for third parameter check box state always are checked i want to load state of checked or unchecked from DB like fifth line :

<td>{{ Form::checkbox('roles[]', $roles->id) }}</td>
astroanu replied 6 months ago

I'm kinda confused as to what you're trying to do here? are you trying to save roles for a user or are you trying to save permissions for each role? This is how normally these three entities relate:

a user has many roles
a role has many permissions
a user has many permission through roles

so you will need a screen with checkboxes to save permissions for a role. and another screen with checkboxes to save roles for a user

asadi20 replied 6 months ago

astroanu said:

I'm kinda confused as to what you're trying to do here? are you trying to save roles for a user or are you trying to save permissions for each role? This is how normally these three entities relate:

a user has many roles ------------------------------------------>yes a role has many permissions--------------------------------->yes a user has many permission through roles-------------->yes

so you will need a screen with checkboxes to save permissions for a role. and another screen with checkboxes to save roles for a user

I want to save both of them in one screen if it is impossible? can you help me how to save permissions for a role

Harsukh replied 1 week ago

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us