laravel - Change roles permission -
i'm trying make admin can decide role can what, frontend easily, i'm bit stuck. i've tried couple of different things, none of them worked far.
i've tried far:
@foreach($role $role) {!! form::model($permission, [ 'method' => 'patch', 'url' => 'settings/permissionsupdate', ]) !!} <br /> {{$role->name}} <br /> <input type="hidden" name="role_id" value="{{ $role->id }}" /> @foreach($permission $perm) <select name="permissions[ {{ $perm->id }} ]"> <option value="1">allowed</option> <option value="0">not allowed</option> </select> <br /> {{$perm->name}} <br /> @endforeach {!! form::submit('save settings', ['class' => 'btn btn-primary']) !!} {!! form::close() !!} @endforeach
ths database
permission_role * id * role_id * permmission_id permission * id * name * slug * description roles * id * name * slug * description role_user * id * role_id * user_id
and controller
public function permissionsupdate(request $request) { $allowed_permissions = []; foreach($request->input('permissions') $permission) { if ($permission == 1) { $allowed_permissions[] = $permission; } $role = role::find($request->input('role_id')); $role->permissions()->sync($allowed_permissions); //currently gives error $role->save(); } }
im getting error call undefined method illuminate\database\query\builder::syncpermission().
models role:
public function permissions() { return $this->hasmany('permissions'); }
permission
public function permissionsrole() { return $this->hasmany('app\permissionrole', 'role_id', 'id'); }
but have admit i'm abit on lost ground. need attach , deatach permissions roles, , can't reallt figure out how this
i still can't seem figure out, tried not sure how i'm gonna attach or deattach permissons users.
update:
i've tried far, , im getting close still few problems.
i had problem of model being wrong, tried finde table role_role changed to
public function permissions() { return $this->belongstomany('app\permission'); (had make new model called permisson, because when used permissions looked role_permissions , called role_permission, table alone called permissions, bit confsuing there) }
and made work, changes first value(1) if on allowed attaches permissons_id equal 1 , role id equal correct role_id, if dd request seems correct data permission_id = 1, 2 ,3 ,4 etc, goes wrong somewhere after that. view still dosen't show allowed or not start. coulndt work, tried like:
<option value="1" {{ @ifusercan($perm->slug) ? 'selected="selected"' : null }} >allowed</option> <option value="0" {{ @ifusercan($perm->slug) ? null : 'selected="selected"' @endif }}>not allowed</option>
but yeah can't that.
Comments
Post a Comment