You are going to need to provide some relevant code if you want help; we have no idea how your project is structured.
Apr 6, 2024
7
Level 3
How do activate and deactivate a role?
I need your help here! I want to deactivate a role in my Laravel 6 project. Currently, every role is active by default. I have added a Status column on my roles page to show whether a role is active or inactive. I am not supposed to see the view button if the logged-in user is not a super Admin. Even if I manually set a role to inactive, I am still able to see the view button, how can I deactivate the role, please? I already have a property status whose value determines whether the role is active or not. How do I change or update the value of the name of a role?
@extends('Layouts.app')
@section('content')
<h1>List of Roles</h1>
<button type="button" class="btn btn-outline-success">
<a href="/roles/create">Create New Role</a>
</button>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Permission</th>
<th scope="col">Action</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
@foreach($roles as $role)
<tr>
<th scope="row">{{ $loop->index + 1 }}</th>
<td>
{{ $role->name }}
</td>
<td>
@foreach($role->permissions as $permission)
{{ $permission->name }}
@endforeach
</td>
<td>
@can('view', $role)
<button type="button" class="btn btn-info">
@if($role->status)
<a href="/roles/{{ $role->id }}">View</a>
@endif
</button>
@endcan
<button type="button" class="btn btn-warning">
<a href="/roles/{{ $role->id}}/edit">Update</a>
</button>
</td>
<td>
<a href="roles/{{ $role->id }}" class="btn btn-sm btn-{{ $role->status ? 'success' : 'danger'}}">
{{ $role->status ? 'active' : '' }}
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<p class="messg">{{ session('messg') }}</p>
@endsection
Please or to participate in this conversation.