Implement roles management;

Add user profile;
Improve Ui;
Clean code;
Minor fix;
Typo;
This commit is contained in:
c.girardi
2024-02-21 16:56:08 +01:00
parent fca756b556
commit e6f3fcbb4e
27 changed files with 708 additions and 138 deletions

View File

@@ -0,0 +1,3 @@
<div>
Price: {{ $user->username }}
</div>

View File

@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<title>{{ config('app.name', 'Motula-Translate') }}</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
@@ -20,6 +20,9 @@
'resources/vendors/flatpickr/flatpickr.min.css',
'resources/vendors/fontawesome/css/all.min.css',
])
@include('layouts.partials.styles')
@stack('head-scripts')
</head>
<body class="font-sans antialiased sidebar-dark">
<div class="main-wrapper">
@@ -28,6 +31,7 @@
<div class="page-wrapper">
@include('layouts.partials.navbar')
<div class="page-content">
@include('layouts.partials.flesh-message')
{{ $slot }}
</div>
@@ -36,6 +40,6 @@
</div>
@include('layouts.partials.scripts')
@stack('body-scripts')
</body>
</html>

View File

@@ -0,0 +1,35 @@
@if ($message = Session::get('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>{{ $message }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if ($message = Session::get('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>{{ $message }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if ($message = Session::get('warning'))
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>{{ $message }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if ($message = Session::get('info'))
<div class="alert alert-info alert-dismissible fade show" role="alert">
<strong>{{ $message }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if ($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Please check the form below for errors</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif

View File

@@ -233,14 +233,24 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="profileDropdown" role="button"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img class="wd-30 ht-30 rounded-circle" src="https://via.placeholder.com/30x30"
alt="profile">
@if(Auth::user()->image)
<img class="wd-30 ht-30 rounded-circle" src="{{asset('/storage/images/'.auth()->user()->image)}}" alt="{{auth()->user()->name}}">
@else
<img class="wd-30 ht-30 rounded-circle" src="https://via.placeholder.com/30x30"
alt="profile">
@endif
</a>
<div class="dropdown-menu p-0" aria-labelledby="profileDropdown">
<div class="d-flex flex-column align-items-center border-bottom px-5 py-3">
<div class="mb-3">
<img class="wd-80 ht-80 rounded-circle" src="https://via.placeholder.com/80x80"
alt="">
@if(Auth::user()->image)
<img class="wd-80 ht-80 rounded-circle" src="{{asset('/storage/images/'.auth()->user()->image)}}" alt="{{auth()->user()->name}}">
@else
<img class="wd-80 ht-80 rounded-circle" src="https://via.placeholder.com/80x80"
alt="profile">
@endif
</div>
<div class="text-center">
<p class="tx-16 fw-bolder">{{ auth()->user()->name }}</p>
@@ -249,13 +259,13 @@
</div>
<ul class="list-unstyled p-1">
<li class="dropdown-item py-2">
<a href="{{route('profile.edit')}}" class="text-body ms-0">
<a href="{{ route('users.show', auth()->user()->id) }}" class="text-body ms-0">
<i class="me-2 icon-md" data-feather="user"></i>
<span>Profile</span>
</a>
</li>
<li class="dropdown-item py-2">
<a href="javascript:;" class="text-body ms-0">
<a href="{{ route('users.edit', auth()->user()->id) }}" class="text-body ms-0">
<i class="me-2 icon-md" data-feather="edit"></i>
<span>Edit Profile</span>
</a>

View File

@@ -14,3 +14,4 @@
<!-- Custom js for this page -->
<script src="/assets/js/dashboard-dark.js"></script>
<!-- End custom js for this page -->
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.full.min.js"></script>

View File

@@ -24,15 +24,21 @@
<span class="link-title">Table Words</span>
</a>
</li>
@if(auth()->user()->hasRole('ADMIN'))
<li class="nav-item nav-category">Admin</li>
<li class="nav-item">
<a class="nav-link" href="{{route('users.index')}}">
<i class="link-icon" data-feather="users"></i>
<span class="link-title">Users</span>
</a>
</li>
@endif
@role('ADMIN')
<li class="nav-item nav-category">Admin</li>
<li class="nav-item">
<a class="nav-link" href="{{route('users.index')}}">
<i class="link-icon fa-regular fa-users"></i>
<span class="link-title">Users</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{route('roles.index')}}">
<i class="link-icon fa-regular fa-user-shield"></i>
<span class="link-title">Roles</span>
</a>
</li>
@endrole
{{-- <li class="nav-item nav-category">web apps</li>--}}
@@ -335,13 +341,13 @@
{{-- </ul>--}}
{{-- </div>--}}
{{-- </li>--}}
<li class="nav-item nav-category">Docs</li>
<li class="nav-item">
<a href="https://www.nobleui.com/html/documentation/docs.html" target="_blank" class="nav-link">
<i class="link-icon" data-feather="hash"></i>
<span class="link-title">Documentation</span>
</a>
</li>
<li class="nav-item nav-category">Docs</li>
<li class="nav-item">
<a href="https://www.nobleui.com/html/documentation/docs.html" target="_blank" class="nav-link">
<i class="link-icon" data-feather="hash"></i>
<span class="link-title">Documentation</span>
</a>
</li>
</ul>
</div>
</nav>

View File

@@ -0,0 +1,2 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" />

View File

@@ -0,0 +1,64 @@
<x-app-layout>
<div class="card">
<div class="card-header">
<div class="float-start">
Add New Role
</div>
<div class="float-end">
<a href="{{ route('roles.index') }}" class="btn btn-primary btn-sm">&larr; Back</a>
</div>
</div>
<div class="card-body">
<form action="{{ route('roles.store') }}" method="post">
@csrf
<div class="mb-3 row">
<label for="name" class="col-md-4 col-form-label text-md-end text-start">Name</label>
<div class="col-md-6">
<input type="text" class="form-control @error('name') is-invalid @enderror" id="name"
name="name" value="{{ old('name') }}">
@if ($errors->has('name'))
<span class="text-danger">{{ $errors->first('name') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<label for="permissions" class="col-md-4 col-form-label text-md-end text-start">Permissions</label>
<div class="col-md-6">
<select class="form-select select-permissions @error('permissions') is-invalid @enderror"
multiple
aria-label="Permissions" id="permissions" name="permissions[]" style="height: 210px;">
@forelse ($permissions as $permission)
<option
value="{{ $permission->id }}" {{ in_array($permission->id, old('permissions') ?? []) ? 'selected' : '' }}>
{{ $permission->name }}
</option>
@empty
@endforelse
</select>
@if ($errors->has('permissions'))
<span class="text-danger">{{ $errors->first('permissions') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<input type="submit" class="col-md-3 offset-md-5 btn btn-primary" value="Add Role">
</div>
</form>
</div>
</div>
@push('body-scripts')
<script id="create-role" type="application/javascript">
$('.select-permissions').select2({
theme: "bootstrap-5",
width: '100%',
});
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,62 @@
<x-app-layout>
<div class="card">
<div class="card-header">
<div class="float-start">
Edit Role
</div>
<div class="float-end">
<a href="{{ route('roles.index') }}" class="btn btn-primary btn-sm">&larr; Back</a>
</div>
</div>
<div class="card-body">
<form action="{{ route('roles.update', $role->id) }}" method="post">
@csrf
@method("PUT")
<div class="mb-3 row">
<label for="name" class="col-md-4 col-form-label text-md-end text-start">Name</label>
<div class="col-md-6">
<input type="text" class="form-control @error('name') is-invalid @enderror" id="name"
name="name" value="{{ $role->name }}">
@if ($errors->has('name'))
<span class="text-danger">{{ $errors->first('name') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<label for="permissions" class="col-md-4 col-form-label text-md-end text-start">Permissions</label>
<div class="col-md-6">
<select class="form-select select-permissions @error('permissions') is-invalid @enderror" multiple
aria-label="Permissions" id="permissions" name="permissions[]" style="height: 210px;">
@forelse ($permissions as $permission)
<option
value="{{ $permission->id }}" {{ in_array($permission->id, $rolePermissions ?? []) ? 'selected' : '' }}>
{{ $permission->name }}
</option>
@empty
@endforelse
</select>
@if ($errors->has('permissions'))
<span class="text-danger">{{ $errors->first('permissions') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<input type="submit" class="col-md-3 offset-md-5 btn btn-primary" value="Update Role">
</div>
</form>
</div>
</div>
@push('body-scripts')
<script id="edit-role" type="application/javascript">
$('.select-permissions').select2({
theme: "bootstrap-5",
width: '100%',
});
</script>
@endpush
</x-app-layout>

View File

@@ -0,0 +1,57 @@
<x-app-layout>
<div class="card">
<div class="card-header">Manage Roles</div>
<div class="card-body">
@can('create-role')
<a href="{{ route('roles.create') }}" class="btn btn-success btn-xs my-2"><i class="bi bi-plus-circle"></i> Add New Role</a>
@endcan
<table class="table table-striped table-hover table-sm">
<thead>
<tr>
<th scope="col">S#</th>
<th scope="col">Name</th>
<th scope="col" style="width: 250px;">Action</th>
</tr>
</thead>
<tbody>
@forelse ($roles as $role)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $role->name }}</td>
<td>
<form action="{{ route('roles.destroy', $role->id) }}" method="post">
@csrf
@method('DELETE')
<a href="{{ route('roles.show', $role->id) }}" class="btn btn-warning btn-xs">Show</a>
@if ($role->name!='ADMIN')
@can('edit-role')
<a href="{{ route('roles.edit', $role->id) }}" class="btn btn-primary btn-xs">Edit</a>
@endcan
@can('delete-role')
@if ($role->name!=Auth::user()->hasRole($role->name))
<button type="submit" class="btn btn-danger btn-xs" onclick="return confirm('Do you want to delete this role?');">Delete</button>
@endif
@endcan
@endif
</form>
</td>
</tr>
@empty
<td colspan="3">
<span class="text-danger">
<strong>No Role Found!</strong>
</span>
</td>
@endforelse
</tbody>
</table>
{{ $roles->links() }}
</div>
</div>
</x-app-layout>

View File

@@ -0,0 +1,35 @@
<x-app-layout>
<div class="card">
<div class="card-header">
<div class="float-start">
Role Information
</div>
<div class="float-end">
<a href="{{ route('roles.index') }}" class="btn btn-primary btn-sm">&larr; Back</a>
</div>
</div>
<div class="card-body">
<div class="mb-3 row">
<label for="name" class="col-md-4 col-form-label text-md-end text-start"><strong>Name:</strong></label>
<div class="col-md-6" style="line-height: 35px;">
{{ $role->name }}
</div>
</div>
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start"><strong>Permissions:</strong></label>
<div class="col-md-6" style="line-height: 35px;">
@if ($role->name=='ADMIN')
<span class="badge bg-primary">All</span>
@else
@forelse ($rolePermissions as $permission)
<span class="badge bg-primary">{{ $permission->name }}</span>
@empty
@endforelse
@endif
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -1,13 +0,0 @@
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
Bla Bla Bla
<?php echo $name; ?>
<?= echo $name; ?>
{{$name}}

View File

@@ -9,7 +9,7 @@
</div>
</div>
<div class="card-body">
<form action="{{ route('users.store') }}" method="post">
<form action="{{ route('users.store') }}" method="post" enctype="multipart/form-data">
@csrf
<div class="mb-3 row">
@@ -59,17 +59,17 @@
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start">Roles</label>
<div class="col-md-6">
<select class="form-select @error('roles') is-invalid @enderror" multiple
<select class="form-select select-roles @error('roles') is-invalid @enderror" multiple
aria-label="Roles" id="roles" name="roles[]">
@forelse ($roles as $role)
@if ($role!='Super Admin')
@if ($role!='ADMIN')
<option
value="{{ $role }}" {{ in_array($role, old('roles') ?? []) ? 'selected' : '' }}>
{{ $role }}
</option>
@else
@if (Auth::user()->hasRole('Super Admin'))
@if (Auth::user()->hasRole('ADMIN'))
<option
value="{{ $role }}" {{ in_array($role, old('roles') ?? []) ? 'selected' : '' }}>
{{ $role }}
@@ -87,6 +87,16 @@
</div>
</div>
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start">Profile Picture</label>
<div class="col-md-6">
<input class="form-control @error('image') is-invalid @enderror" type="file" name="image">
@if ($errors->has('image'))
<span class="text-danger">{{ $errors->first('image') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<input type="submit" class="col-md-3 offset-md-5 btn btn-primary" value="Add User">
</div>
@@ -94,4 +104,15 @@
</form>
</div>
</div>
@push('body-scripts')
<script id="create-user" type="application/javascript">
$('.select-roles').select2({
theme: "bootstrap-5",
width: '100%',
});
</script>
@endpush
</x-app-layout>

View File

@@ -7,92 +7,112 @@
<div class="float-end">
<a href="{{ route('users.index') }}" class="btn btn-primary btn-xs"> Back</a>
</div>
<div class="card-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
@csrf
@method("PUT")
</div>
<div class="card-body">
<form action="{{ route('users.update', $user->id) }}" method="post" enctype="multipart/form-data">
@csrf
@method("PUT")
<div class="mb-3 row">
<label for="name" class="col-md-4 col-form-label text-md-end text-start">Name</label>
<div class="col-md-6">
<input type="text" class="form-control @error('name') is-invalid @enderror" id="name"
name="name" value="{{ $user->name }}">
@if ($errors->has('name'))
<span class="text-danger">{{ $errors->first('name') }}</span>
@endif
</div>
<div class="mb-3 row">
<label for="name" class="col-md-4 col-form-label text-md-end text-start">Name</label>
<div class="col-md-6">
<input type="text" class="form-control @error('name') is-invalid @enderror" id="name"
name="name" value="{{ $user->name }}">
@if ($errors->has('name'))
<span class="text-danger">{{ $errors->first('name') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<label for="email" class="col-md-4 col-form-label text-md-end text-start">Email
Address</label>
<div class="col-md-6">
<input type="email" class="form-control @error('email') is-invalid @enderror" id="email"
name="email" value="{{ $user->email }}">
@if ($errors->has('email'))
<span class="text-danger">{{ $errors->first('email') }}</span>
@endif
</div>
<div class="mb-3 row">
<label for="email" class="col-md-4 col-form-label text-md-end text-start">Email
Address</label>
<div class="col-md-6">
<input type="email" class="form-control @error('email') is-invalid @enderror" id="email"
name="email" value="{{ $user->email }}">
@if ($errors->has('email'))
<span class="text-danger">{{ $errors->first('email') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<label for="password"
class="col-md-4 col-form-label text-md-end text-start">Password</label>
<div class="col-md-6">
<input type="password" class="form-control @error('password') is-invalid @enderror"
id="password" name="password">
@if ($errors->has('password'))
<span class="text-danger">{{ $errors->first('password') }}</span>
@endif
</div>
<div class="mb-3 row">
<label for="password"
class="col-md-4 col-form-label text-md-end text-start">Password</label>
<div class="col-md-6">
<input type="password" class="form-control @error('password') is-invalid @enderror"
id="password" name="password">
@if ($errors->has('password'))
<span class="text-danger">{{ $errors->first('password') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<label for="password_confirmation" class="col-md-4 col-form-label text-md-end text-start">Confirm
Password</label>
<div class="col-md-6">
<input type="password" class="form-control" id="password_confirmation"
name="password_confirmation">
</div>
<div class="mb-3 row">
<label for="password_confirmation" class="col-md-4 col-form-label text-md-end text-start">Confirm
Password</label>
<div class="col-md-6">
<input type="password" class="form-control" id="password_confirmation"
name="password_confirmation">
</div>
</div>
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start">Roles</label>
<div class="col-md-6">
<select class="form-select @error('roles') is-invalid @enderror" multiple
aria-label="Roles" id="roles" name="roles[]">
@forelse ($roles as $role)
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start">Roles</label>
<div class="col-md-6">
<select class="form-select select-roles @error('roles') is-invalid @enderror" multiple
aria-label="Roles" id="roles" name="roles[]">
@forelse ($roles as $role)
@if ($role!='Super Admin')
@if ($role!='ADMIN')
<option
value="{{ $role }}" {{ in_array($role, $userRoles ?? []) ? 'selected' : '' }}>
{{ $role }}
</option>
@else
@if (Auth::user()->hasRole('ADMIN'))
<option
value="{{ $role }}" {{ in_array($role, $userRoles ?? []) ? 'selected' : '' }}>
{{ $role }}
</option>
@else
@if (Auth::user()->hasRole('Super Admin'))
<option
value="{{ $role }}" {{ in_array($role, $userRoles ?? []) ? 'selected' : '' }}>
{{ $role }}
</option>
@endif
@endif
@endif
@empty
@empty
@endforelse
</select>
@if ($errors->has('roles'))
<span class="text-danger">{{ $errors->first('roles') }}</span>
@endif
</div>
@endforelse
</select>
@if ($errors->has('roles'))
<span class="text-danger">{{ $errors->first('roles') }}</span>
@endif
</div>
</div>
<div class="mb-3 row">
<input type="submit" class="col-md-3 offset-md-5 btn btn-primary" value="Update User">
<div class="mb-3 row">
<label for="roles" class="col-md-4 col-form-label text-md-end text-start">Profile Picture</label>
<div class="col-md-6">
<input class="form-control @error('image') is-invalid @enderror" type="file" name="image">
@if ($errors->has('image'))
<span class="text-danger">{{ $errors->first('image') }}</span>
@endif
</div>
</div>
</form>
</div>
<div class="mb-3 row">
<input type="submit" class="col-md-3 offset-md-5 btn btn-primary" value="Update User">
</div>
</form>
</div>
</div>
@push('body-scripts')
<script id="edit-user" type="application/javascript">
$('.select-roles').select2({
theme: "bootstrap-5",
width: '100%',
});
</script>
@endpush
</x-app-layout>