Update Role & Permission Module

This commit is contained in:
Daeng Deni Mardaeni 2023-04-17 09:58:29 +07:00
parent 54ed252e3f
commit 6c1635804c
14 changed files with 212 additions and 684 deletions

View File

@ -79,6 +79,7 @@ class PermissionsController extends Controller
]; ];
foreach($data as $permission){ foreach($data as $permission){
Permission::create([ Permission::create([
'name' => $permission, 'name' => $permission,
'guard_name' => 'web', 'guard_name' => 'web',
@ -149,6 +150,7 @@ class PermissionsController extends Controller
$group->name = $request->name; $group->name = $request->name;
if($group->save()){ if($group->save()){
$group_name = strtolower($request->name);
$permissions = Permission::where('permission_group_id', $group->id)->get(); $permissions = Permission::where('permission_group_id', $group->id)->get();
$data = [ $data = [

View File

@ -1,19 +1,21 @@
<?php <?php
namespace App\Http\Controllers\Users; namespace App\Http\Controllers\Users;
use App\DataTables\Users\RolesDataTable; use App\DataTables\Users\RolesDataTable;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\PermissionGroup; use App\Models\PermissionGroup;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Exception;
use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Http\Response;
use Spatie\Permission\Models\Role; use Illuminate\Support\Facades\Auth;
use App\Models\Permission; use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Role;
use App\Models\Permission;
class RolesController extends Controller class RolesController extends Controller
{ {
public $user; public $user;
public function __construct() public function __construct()
@ -27,7 +29,7 @@
/** /**
* Display a listing of the resource. * Display a listing of the resource.
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function index(RolesDataTable $dataTable) public function index(RolesDataTable $dataTable)
{ {
@ -42,7 +44,7 @@
/** /**
* Show the form for creating a new resource. * Show the form for creating a new resource.
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function create() public function create()
{ {
@ -51,9 +53,9 @@
/** /**
* Store a newly created resource in storage. * Store a newly created resource in storage.
* *
* @param \Illuminate\Http\Request $request * @param Request $request
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function store(Request $request) public function store(Request $request)
{ {
@ -69,7 +71,7 @@
]); ]);
if($validated){ if ($validated) {
try { try {
// Process Data // Process Data
$role = Role::create(['name' => $request->name, 'guard_name' => 'web']); $role = Role::create(['name' => $request->name, 'guard_name' => 'web']);
@ -82,7 +84,7 @@
} }
echo json_encode(['status' => 'success', 'message' => 'Role Created Successfully']); echo json_encode(['status' => 'success', 'message' => 'Role Created Successfully']);
} catch (\Exception $e) { } catch (Exception $e) {
echo json_encode(['status' => 'error', 'message' => 'Role Created Failed']); echo json_encode(['status' => 'error', 'message' => 'Role Created Failed']);
} }
} }
@ -95,7 +97,7 @@
* *
* @param int $id * @param int $id
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function show($id) public function show($id)
{ {
@ -107,7 +109,7 @@
* *
* @param int $id * @param int $id
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function edit($id) public function edit($id)
{ {
@ -124,19 +126,17 @@
'permissions' => $permissions, 'permissions' => $permissions,
'permissiongroups' => $permissiongroups 'permissiongroups' => $permissiongroups
]; ];
setcookie('role', json_encode($role), time() + (86400 * 30), "/");
setcookie('perissions', json_encode($permissions), time() + (86400 * 30), "/");
echo json_encode($_array); return view('pages.users.roles.edit', $_array);
} }
/** /**
* Update the specified resource in storage. * Update the specified resource in storage.
* *
* @param \Illuminate\Http\Request $request * @param Request $request
* @param int $id * @param int $id
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
@ -170,7 +170,7 @@
* *
* @param int $id * @param int $id
* *
* @return \Illuminate\Http\Response * @return Response
*/ */
public function destroy($id) public function destroy($id)
{ {
@ -187,4 +187,4 @@
session()->flash('success', 'Role has been deleted !!'); session()->flash('success', 'Role has been deleted !!');
return redirect()->route('user.roles.index'); return redirect()->route('user.roles.index');
} }
} }

13
composer.lock generated
View File

@ -3693,16 +3693,16 @@
}, },
{ {
"name": "ramsey/uuid", "name": "ramsey/uuid",
"version": "4.x-dev", "version": "4.7.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/ramsey/uuid.git", "url": "https://github.com/ramsey/uuid.git",
"reference": "8e955307d32dc9b6992440ff81321d3cb09db75a" "reference": "60a4c63ab724854332900504274f6150ff26d286"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/ramsey/uuid/zipball/8e955307d32dc9b6992440ff81321d3cb09db75a", "url": "https://api.github.com/repos/ramsey/uuid/zipball/60a4c63ab724854332900504274f6150ff26d286",
"reference": "8e955307d32dc9b6992440ff81321d3cb09db75a", "reference": "60a4c63ab724854332900504274f6150ff26d286",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3743,7 +3743,6 @@
"paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter", "paragonie/random-lib": "Provides RandomLib for use with the RandomLibAdapter",
"ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type." "ramsey/uuid-doctrine": "Allows the use of Ramsey\\Uuid\\Uuid as Doctrine field type."
}, },
"default-branch": true,
"type": "library", "type": "library",
"extra": { "extra": {
"captainhook": { "captainhook": {
@ -3770,7 +3769,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/ramsey/uuid/issues", "issues": "https://github.com/ramsey/uuid/issues",
"source": "https://github.com/ramsey/uuid/tree/4.x" "source": "https://github.com/ramsey/uuid/tree/4.7.4"
}, },
"funding": [ "funding": [
{ {
@ -3782,7 +3781,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-03-27T22:05:11+00:00" "time": "2023-04-15T23:01:58+00:00"
}, },
{ {
"name": "spatie/laravel-activitylog", "name": "spatie/laravel-activitylog",

View File

@ -1,14 +0,0 @@
<div class="d-flex flex-row flex-center">
@if(Auth::user()->can('role.update'))
<a href="{{ route('roles.edit',['role' => $model->id]) }}"
class="btn btn-bg-light btn-active-light-primary btn-sm me-1" data-bs-toggle="tooltip" data-bs-custom-class="tooltip-dark" data-bs-placement="top" title="Edit">
{!! theme()->getSvgIcon("icons/duotune/art/art005.svg", "svg-icon-3") !!} Edit
</a>
@endif
@if($model->id > 5 && Auth::user()->can('role.delete'))
{!! Form::open(['method' => 'DELETE','route' => ['roles.destroy', $model->id],'class'=>'']) !!}
{{ Form::button(theme()->getSvgIcon("icons/duotune/general/gen027.svg", "svg-icon-3")." Delete", ['type' => 'submit', 'class' => 'delete btn btn-bg-light btn-active-light-danger btn-sm', 'data-bs-toggle' => "tooltip", 'data-bs-custom-class' => "tooltip-dark", 'data-bs-placement'=>"top", 'title'=>"Delete"] ) }}
{!! Form::close() !!}
@endif
</div>

View File

@ -1,5 +0,0 @@
<td>
<div class="form-check form-check-sm form-check-custom form-check-solid">
<input class="form-check-input widget-9-check" name="id[]" type="checkbox" value="{{ $model->id() }}"/>
</div>
</td>

View File

@ -1,132 +0,0 @@
<form id="kt_modal_add_role_form" method="POST" class="form" action="{{ route('roles.store') }}">
{{ csrf_field() }}
<!--begin::Scroll-->
<div class="d-flex flex-column flex-row-fluid" id="kt_modal_add_role_scroll" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_modal_add_role_header" data-kt-scroll-wrappers="#kt_modal_add_role_scroll" data-kt-scroll-offset="300px">
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Role Name</label>
<!--end::Label-->
<!--begin::Input-->
<div class="input-group input-group-solid has-validation mb-3">
<input type="text" name="name" class="form-control form-control-solid mb-3 mb-lg-0 @error('name') is-invalid @enderror" placeholder="Role name" value="" />
</div>
@error('name')
<div class="text-danger">{{ $message }}</div>
@enderror
<!--end::Input-->
</div>
<!--end::Input group-->
<div class="fv-row">
<!--begin::Label-->
<label class="fs-5 fw-bolder form-label mb-2">Role Permissions</label>
<!--end::Label-->
<!--begin::Table wrapper-->
<div class="table-responsive">
<!--begin::Table-->
<table class="table align-middle table-row-dashed fs-6 gy-5">
<!--begin::Table body-->
<tbody class="text-gray-600 fw-bold">
<!--begin::Table row-->
<tr>
<td class="text-gray-800">Administrator/Superuser Access
<i class="fas fa-exclamation-circle ms-1 fs-7" data-bs-toggle="tooltip" title="Allows a full access to the system"></i></td>
<td>
<!--begin::Checkbox-->
<label class="form-check form-check-sm form-check-custom form-check-solid me-9">
<input class="form-check-input" type="checkbox" value="" id="kt_roles_select_all" />
<span class="form-check-label" for="kt_roles_select_all">Select all</span>
</label>
<!--end::Checkbox-->
</td>
</tr>
<!--end::Table row-->
@foreach($permissiongroups as $group)
<!--begin::Table row-->
<tr>
<!--begin::Label-->
<td class="text-gray-800">{{ $group->name }}</td>
<!--end::Label-->
<!--begin::Input group-->
<td>
<!--begin::Wrapper-->
<div class="d-flex">
@foreach($group->getpermissionsByGroupId($group->id) as $permission)
<!--begin::Checkbox-->
<label class="form-check form-check-sm form-check-custom form-check-solid me-5 me-lg-20">
<input class="form-check-input" type="checkbox" value="{{ $permission->id }}" name="permissions[]" />
@php
$permission_name = explode('.',$permission->name);
@endphp
<span class="form-check-label text-capitalize">{{ $permission_name[1] }}</span>
</label>
<!--end::Checkbox-->
@endforeach
</div>
<!--end::Wrapper-->
</td>
<!--end::Input group-->
</tr>
<!--end::Table row-->
@endforeach
</tbody>
<!--end::Table body-->
</table>
<!--end::Table-->
</div>
<!--end::Table wrapper-->
</div>
<!--end::Permissions-->
</div>
<!--end::Scroll-->
<!--begin::Actions-->
<div class="text-center pt-15">
<button type="reset" class="btn btn-light me-3" data-kt-roles-modal-action="cancel">Discard</button>
<button type="submit" class="btn btn-primary" data-kt-roles-modal-action="submit">
<span class="indicator-label">Submit</span>
<span class="indicator-progress">Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
</button>
</div>
<!--end::Actions-->
</form>
@push('customscript')
<script>
"use strict";
// Class definition
var Roles = function () {
// Shared variables
const form = document.getElementById('kt_modal_add_role_form');
// Select all handler
const handleSelectAll = () => {
// Define variables
const selectAll = form.querySelector('#kt_roles_select_all');
const allCheckboxes = form.querySelectorAll('[type="checkbox"]');
// Handle check state
selectAll.addEventListener('change', e => {
// Apply check state to all checkboxes
allCheckboxes.forEach(c => {
c.checked = e.target.checked;
});
});
}
return {
// Public functions
init: function () {
handleSelectAll();
}
};
}();
// On document ready
KTUtil.onDOMContentLoaded(function () {
Roles.init();
});
</script>
@endpush

View File

@ -1,164 +0,0 @@
@php
$route = explode('.', Route::currentRouteName());
@endphp
<!--begin::Modal - New Target-->
<div class="modal fade" id="kt_modal_user_roles" tabindex="-1" aria-hidden="true">
<!--begin::Modal dialog-->
<div class="modal-dialog modal-dialog-centered mw-650px">
<!--begin::Modal content-->
<div class="modal-content rounded">
<!--begin::Modal header-->
<div class="modal-header pb-0 border-0 justify-content-end">
<!--begin::Close-->
<div class="btn btn-sm btn-icon btn-active-color-primary" data-bs-dismiss="modal">{!! getIcon('cross', 'fs-1') !!}</div>
<!--end::Close-->
</div>
<!--begin::Modal header-->
<!--begin::Modal body-->
<div class="modal-body scroll-y px-10 px-lg-15 pt-0 pb-15">
<!--begin:Form-->
<form class="form_{{$route[0]}}_{{$route[1]}}" method="POST" action="{{ route($route[0].'.'.$route[1].'.store') }}">
@csrf
<!--begin::Heading-->
<div class="mb-13 text-center">
<!--begin::Title-->
<h1 class="mb-3 text-capitalize" id="title_form">{{ str_replace('-',' ',$route[0].' '.$route[1]) }}</h1>
<!--end::Title-->
</div>
<!--end::Heading-->
<!--begin::Scroll-->
<div class="d-flex flex-column flex-row-fluid" id="kt_modal_add_role_scroll" data-kt-scroll="true" data-kt-scroll-activate="{default: false, lg: true}" data-kt-scroll-max-height="auto" data-kt-scroll-dependencies="#kt_modal_add_role_header" data-kt-scroll-wrappers="#kt_modal_add_role_scroll" data-kt-scroll-offset="300px">
<!--begin::Input group-->
<div class="fv-row mb-7">
<!--begin::Label-->
<label class="required fw-bold fs-6 mb-2">Role Name</label>
<!--end::Label-->
<!--begin::Input-->
<div class="input-group input-group-solid has-validation mb-3">
<input type="text" name="name" class="form-control form-control-solid mb-3 mb-lg-0 @error('name') is-invalid @enderror" placeholder="Role name" value="" />
</div>
@error('name')
<div class="text-danger">{{ $message }}</div>
@enderror
<!--end::Input-->
</div>
<!--end::Input group-->
<div class="fv-row">
<!--begin::Label-->
<label class="fs-5 fw-bolder form-label mb-2">Role Permissions</label>
<!--end::Label-->
<!--begin::Table wrapper-->
<div class="table-responsive">
<!--begin::Table-->
<table class="table align-middle table-row-dashed fs-6 gy-5">
<!--begin::Table body-->
<tbody class="text-gray-600 fw-bold">
<!--begin::Table row-->
<tr>
<td class="text-gray-800">Administrator/Superuser Access
<i class="fas fa-exclamation-circle ms-1 fs-7" data-bs-toggle="tooltip" title="Allows a full access to the system"></i></td>
<td>
<!--begin::Checkbox-->
<label class="form-check form-check-sm form-check-custom form-check-solid me-9">
<input class="form-check-input" type="checkbox" value="" id="kt_roles_select_all" />
<span class="form-check-label" for="kt_roles_select_all">Select all</span>
</label>
<!--end::Checkbox-->
</td>
</tr>
<!--end::Table row-->
@foreach($permissiongroups as $group)
<!--begin::Table row-->
<tr>
<!--begin::Label-->
<td class="text-gray-800">{{ $group->name }}</td>
<!--end::Label-->
<!--begin::Input group-->
<td>
<!--begin::Wrapper-->
<div class="d-flex">
@foreach($group->getpermissionsByGroupId($group->id) as $permission)
<!--begin::Checkbox-->
<label class="form-check form-check-sm form-check-custom form-check-solid me-5 me-lg-20">
<input class="form-check-input" type="checkbox" value="{{ $permission->id }}" name="permissions[]" />
@php
$permission_name = explode('.',$permission->name);
@endphp
<span class="form-check-label text-capitalize">{{ $permission_name[1] }}</span>
</label>
<!--end::Checkbox-->
@endforeach
</div>
<!--end::Wrapper-->
</td>
<!--end::Input group-->
</tr>
<!--end::Table row-->
@endforeach
</tbody>
<!--end::Table body-->
</table>
<!--end::Table-->
</div>
<!--end::Table wrapper-->
</div>
<!--end::Permissions-->
</div>
<!--end::Scroll-->
<!--begin::Actions-->
<div class="text-center">
<button type="reset" data-bs-dismiss="modal" class="btn btn-light me-3">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
<!--end::Actions-->
</form>
<!--end:Form-->
</div>
<!--end::Modal body-->
</div>
<!--end::Modal content-->
</div>
<!--end::Modal dialog-->
</div>
<!--end::Modal - New Target-->
@push('customscript')
<script>
"use strict";
// Class definition
var Roles = function () {
// Shared variables
const form = document.getElementById('kt_modal_add_role_form');
// Select all handler
const handleSelectAll = () => {
// Define variables
const selectAll = form.querySelector('#kt_roles_select_all');
const allCheckboxes = form.querySelectorAll('[type="checkbox"]');
// Handle check state
selectAll.addEventListener('change', e => {
// Apply check state to all checkboxes
allCheckboxes.forEach(c => {
c.checked = e.target.checked;
});
});
}
return {
// Public functions
init: function () {
handleSelectAll();
}
};
}();
// On document ready
KTUtil.onDOMContentLoaded(function () {
Roles.init();
});
</script>
@endpush

View File

@ -1,50 +0,0 @@
<!--begin::Table-->
{{ $dataTable->table() }}
<!--end::Table-->
{{-- Inject Scripts --}}
@section('scripts')
{{ $dataTable->scripts() }}
@endsection
@push('customscript')
<script>
$("#searchbox").on("keyup search input paste cut", function() {
LaravelDataTables["roles-table"].search(this.value).draw();
});
$(function(){
LaravelDataTables["roles-table"].on('click','.delete',function(event){
var form = $(this).closest("form");
event.preventDefault();
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
form.submit();
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})
})
})
</script>
@endpush
@section('styles')
<style>
.dataTables_filter {
display: none;
}
</style>
@endsection

View File

@ -1,29 +0,0 @@
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
<!--begin::Card body-->
<div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column">
Add Role
</h3>
<div class="card-toolbar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-trigger="hover" title=""
data-bs-original-title="Click to cancel">
<a href="{{ route('roles.index') }}" class="btn btn-sm btn-light-primary">
<!--begin::Svg Icon | path: assets/media/icons/duotune/arrows/arr079.svg-->
<span class="svg-icon svg-icon-muted svg-icon-2hx"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path opacity="0.5" d="M14.2657 11.4343L18.45 7.25C18.8642 6.83579 18.8642 6.16421 18.45 5.75C18.0358 5.33579 17.3642 5.33579 16.95 5.75L11.4071 11.2929C11.0166 11.6834 11.0166 12.3166 11.4071 12.7071L16.95 18.25C17.3642 18.6642 18.0358 18.6642 18.45 18.25C18.8642 17.8358 18.8642 17.1642 18.45 16.75L14.2657 12.5657C13.9533 12.2533 13.9533 11.7467 14.2657 11.4343Z" fill="currentColor"/>
<path d="M8.2657 11.4343L12.45 7.25C12.8642 6.83579 12.8642 6.16421 12.45 5.75C12.0358 5.33579 11.3642 5.33579 10.95 5.75L5.40712 11.2929C5.01659 11.6834 5.01659 12.3166 5.40712 12.7071L10.95 18.25C11.3642 18.6642 12.0358 18.6642 12.45 18.25C12.8642 17.8358 12.8642 17.1642 12.45 16.75L8.2657 12.5657C7.95328 12.2533 7.95328 11.7467 8.2657 11.4343Z" fill="currentColor"/>
</svg></span>
<!--end::Svg Icon-->
Cancel
</a>
</div>
</div>
<div class="card-body pt-6">
@include('pages.roles._createform')
</div>
<!--end::Card body-->
</div>
<!--end::Card-->
</x-default-layout>

View File

@ -1,29 +0,0 @@
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
<!--begin::Card body-->
<div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column">
Edit Role {{ $role->name }}
</h3>
<div class="card-toolbar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-trigger="hover" title=""
data-bs-original-title="Click to cancel">
<a href="{{ route('roles.index') }}" class="btn btn-sm btn-light-primary">
<!--begin::Svg Icon | path: assets/media/icons/duotune/arrows/arr079.svg-->
<span class="svg-icon svg-icon-muted svg-icon-2hx"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
<path opacity="0.5" d="M14.2657 11.4343L18.45 7.25C18.8642 6.83579 18.8642 6.16421 18.45 5.75C18.0358 5.33579 17.3642 5.33579 16.95 5.75L11.4071 11.2929C11.0166 11.6834 11.0166 12.3166 11.4071 12.7071L16.95 18.25C17.3642 18.6642 18.0358 18.6642 18.45 18.25C18.8642 17.8358 18.8642 17.1642 18.45 16.75L14.2657 12.5657C13.9533 12.2533 13.9533 11.7467 14.2657 11.4343Z" fill="currentColor"/>
<path d="M8.2657 11.4343L12.45 7.25C12.8642 6.83579 12.8642 6.16421 12.45 5.75C12.0358 5.33579 11.3642 5.33579 10.95 5.75L5.40712 11.2929C5.01659 11.6834 5.01659 12.3166 5.40712 12.7071L10.95 18.25C11.3642 18.6642 12.0358 18.6642 12.45 18.25C12.8642 17.8358 12.8642 17.1642 12.45 16.75L8.2657 12.5657C7.95328 12.2533 7.95328 11.7467 8.2657 11.4343Z" fill="currentColor"/>
</svg></span>
<!--end::Svg Icon-->
Cancel
</a>
</div>
</div>
<div class="card-body pt-6">
@include('pages.roles._editform')
</div>
<!--end::Card body-->
</div>
<!--end::Card-->
</x-default-layout>

View File

@ -1,52 +0,0 @@
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
<!--begin::Card body-->
<div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column">
<div class="d-flex align-items-center position-relative my-1">
<!--begin::Svg Icon | path: icons/duotune/general/gen021.svg-->
<span class="svg-icon svg-icon-1 position-absolute ms-6">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
viewBox="0 0 24 24" fill="none">
<rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546"
height="2" rx="1" transform="rotate(45 17.0365 15.1223)"
fill="currentColor"></rect>
<path
d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z"
fill="currentColor"></path>
</svg>
</span>
<!--end::Svg Icon-->
<input type="text" id="searchbox" class="form-control form-control-solid w-250px ps-15"
placeholder="Search Roles">
</div>
</h3>
@if(Auth::user()->can('role.create'))
<div class="card-toolbar" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-trigger="hover"
title=""
data-bs-original-title="Click to add a role">
<a href="{{ route('roles.create') }}" class="btn btn-sm btn-light-primary">
<!--begin::Svg Icon | path: /var/www/preview.keenthemes.com/kt-products/metronic/releases/2022-07-14-092914/core/html/src/media/icons/duotune/arrows/arr013.svg-->
<span class="svg-icon svg-icon-muted svg-icon-2hx">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.3" d="M11 13H7C6.4 13 6 12.6 6 12C6 11.4 6.4 11 7 11H11V13ZM17 11H13V13H17C17.6 13 18 12.6 18 12C18 11.4 17.6 11 17 11Z" fill="currentColor"/>
<path d="M22 12C22 17.5 17.5 22 12 22C6.5 22 2 17.5 2 12C2 6.5 6.5 2 12 2C17.5 2 22 6.5 22 12ZM17 11H13V7C13 6.4 12.6 6 12 6C11.4 6 11 6.4 11 7V11H7C6.4 11 6 11.4 6 12C6 12.6 6.4 13 7 13H11V17C11 17.6 11.4 18 12 18C12.6 18 13 17.6 13 17V13H17C17.6 13 18 12.6 18 12C18 11.4 17.6 11 17 11Z" fill="currentColor"/>
</svg>
</span>
<!--end::Svg Icon-->
New Role
</a>
</div>
@endif
</div>
<div class="card-body pt-6">
@include('pages.users.roles._table')
@include('pages.users.roles._form')
</div>
<!--end::Card body-->
</div>
<!--end::Card-->
</x-default-layout>

View File

@ -1,4 +1,4 @@
<form id="kt_modal_add_role_form" method="POST" class="form" action="{{ route('roles.update',['role' => $role->id]) }}"> <form id="kt_modal_add_role_form" method="POST" class="form" action="{{ route('user.roles.update',['role' => $role->id]) }}">
@method('PUT') @method('PUT')
{{ csrf_field() }} {{ csrf_field() }}
<!--begin::Scroll--> <!--begin::Scroll-->
@ -87,7 +87,9 @@
<!--end::Scroll--> <!--end::Scroll-->
<!--begin::Actions--> <!--begin::Actions-->
<div class="text-center pt-15"> <div class="text-center pt-15">
<button type="reset" class="btn btn-light me-3" data-kt-roles-modal-action="cancel">Discard</button> <a href="{{ route('user.roles.index') }}" class="btn btn-light-primary">
Cancel
</a>
<button type="submit" class="btn btn-primary" data-kt-roles-modal-action="submit"> <button type="submit" class="btn btn-primary" data-kt-roles-modal-action="submit">
<span class="indicator-label">Submit</span> <span class="indicator-label">Submit</span>
<span class="indicator-progress">Please wait... <span class="indicator-progress">Please wait...

View File

@ -59,22 +59,6 @@
}); });
}); });
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click','.kt_edit_form',function(event){
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
type: 'GET',
dataType: 'json',
success: function (response) {
$('#title_form').text('Edit {{ ucfirst(str_replace('-',' ',$route[0].' '.$route[1])) }}');
$('#{{$route[0].'_'.$route[1]}}_id').val(response.role.id);
$('#{{$route[0].'_'.$route[1]}}_name').val(response.role.name);
$('.form_{{$route[0].'_'.$route[1]}}').attr('action', '{{ URL::to('/'.$route[0].'/'.$route[1].'/') }}/' + response.id).append('<input type="hidden" name="_method" value="PUT">');
$('#kt_modal_{{$route[0].'_'.$route[1]}}').modal('show');
}
})
})
LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.delete', function (event) { LaravelDataTables["{{$route[0].'-'.$route[1]}}-table"].on('click', '.delete', function (event) {
var form = $(this).closest("form"); var form = $(this).closest("form");
event.preventDefault(); event.preventDefault();

View File

@ -0,0 +1,16 @@
<x-default-layout>
<!--begin::Card-->
<div class="card card-xxl-stretch mb-5 mb-xl-8">
<!--begin::Card body-->
<div class="card-header border-0 pt-5">
<h3 class="card-title align-items-start flex-column">
Edit Role {{ $role->name }}
</h3>
</div>
<div class="card-body pt-6">
@include('pages.users.roles._editform')
</div>
<!--end::Card body-->
</div>
<!--end::Card-->
</x-default-layout>