diff --git a/app/Http/Controllers/Superuser/PermissionController.php b/app/Http/Controllers/Superuser/PermissionController.php
new file mode 100644
index 0000000..18a3b3b
--- /dev/null
+++ b/app/Http/Controllers/Superuser/PermissionController.php
@@ -0,0 +1,98 @@
+validate([
+ 'name' => 'required|string|unique:permissions',
+ ]);
+
+ if ($permission = Permission::create([ 'name' => $request->name, 'guard_name' => 'web' ])) {
+ return redirect()->back()->with('success', __(
+ 'permission `:name` has been created', [
+ 'name' => $permission->name,
+ ]
+ ));
+ }
+
+ return redirect()->back()->with('error', __(
+ 'can\'t create permission'
+ ));
+ }
+
+ /**
+ * Update the specified resource in storage.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param \App\Models\Permission $permission
+ * @return \Illuminate\Http\Response
+ */
+ public function update(Request $request, Permission $permission)
+ {
+ $request->validate([
+ 'name' => ['required', 'string', Rule::unique('permissions')->ignore($permission->id)]
+ ]);
+
+ if ($permission->update(['name' => $request->name])) {
+ return redirect()->back()->with('success', __(
+ 'permission has been updated',
+ ));
+ }
+
+ return redirect()->back()->with('error', __(
+ 'can\'t update permission'
+ ));
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ *
+ * @param \App\Models\Permission $permission
+ * @return \Illuminate\Http\Response
+ */
+ public function destroy(Permission $permission)
+ {
+ if ($permission->delete()) {
+ return redirect()->back()->with('success', __(
+ 'permission has been deleted'
+ ));
+ }
+
+ return redirect()->back()->with('error', __(
+ 'can\'t delete permission'
+ ));
+ }
+}
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 3d219ed..3dda92a 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -64,5 +64,7 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
+ 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
+ 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
];
}
diff --git a/resources/js/Layouts/DashboardLayout.vue b/resources/js/Layouts/DashboardLayout.vue
index 4d27615..e177585 100644
--- a/resources/js/Layouts/DashboardLayout.vue
+++ b/resources/js/Layouts/DashboardLayout.vue
@@ -1,6 +1,6 @@
+
+
diff --git a/resources/js/Pages/Superuser/Permission/Index.vue b/resources/js/Pages/Superuser/Permission/Index.vue
new file mode 100644
index 0000000..4aa4300
--- /dev/null
+++ b/resources/js/Pages/Superuser/Permission/Index.vue
@@ -0,0 +1,183 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{ permission.name }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/resources/js/app.js b/resources/js/app.js
index e57e5eb..77656a7 100644
--- a/resources/js/app.js
+++ b/resources/js/app.js
@@ -2,11 +2,13 @@ import './bootstrap';
import '../css/app.css';
import { createApp, h } from 'vue';
-import { createInertiaApp } from '@inertiajs/inertia-vue3';
+import { createInertiaApp, usePage } from '@inertiajs/inertia-vue3';
import { InertiaProgress } from '@inertiajs/progress';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
import Themes from './themes'
+import Swal from 'sweetalert2';
+import { Inertia } from '@inertiajs/inertia';
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
@@ -27,3 +29,54 @@ createInertiaApp({
});
InertiaProgress.init({ color: '#4B5563' });
+
+window.Swal = Swal
+const Toast = Swal.mixin({
+ toast: true,
+ position: 'top-end',
+ showConfirmButton: false,
+ showCloseButton: true,
+ timerProgressBar: true,
+ didOpen: (toast) => {
+ toast.addEventListener('mouseenter', Swal.stopTimer)
+ toast.addEventListener('mouseleave', Swal.resumeTimer)
+ }
+})
+
+window.Toast = Toast
+
+Inertia.on('finish', () => {
+ const { $flash } = usePage().props.value
+ const { success, error, info, warning } = $flash
+
+ if (success) {
+ Toast.fire({
+ text: success,
+ timer: 3000,
+ icon: 'success',
+ })
+ }
+
+ if (error) {
+ Toast.fire({
+ text: error,
+ icon: 'error',
+ })
+ }
+
+ if (info) {
+ Toast.fire({
+ text: info,
+ timer: 3000,
+ icon: 'info',
+ })
+ }
+
+ if (warning) {
+ Toast.fire({
+ text: warning,
+ timer: 3000,
+ icon: 'warning',
+ })
+ }
+})
\ No newline at end of file
diff --git a/routes/api.php b/routes/api.php
index ff8c456..4e247d5 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -16,4 +16,8 @@ use Illuminate\Support\Facades\Route;
Route::prefix('/v1')->name('api.v1.')->group(function () {
Route::get('/user/{user}/menu', fn (App\Models\User $user) => $user->menus())->name('user.menu');
+
+ Route::name('superuser.')->group(function () {
+ Route::get('/superuser/permission', [App\Http\Controllers\Superuser\PermissionController::class, 'get'])->name('permission');
+ });
});
\ No newline at end of file
diff --git a/routes/web.php b/routes/web.php
index ba13b47..b837044 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -15,21 +15,14 @@ use Inertia\Inertia;
|
*/
-Route::get('/', function () {
- return Inertia::render('Welcome', [
- 'canLogin' => Route::has('login'),
- 'canRegister' => Route::has('register'),
- 'laravelVersion' => Application::VERSION,
- 'phpVersion' => PHP_VERSION,
- ]);
-});
-
-Route::middleware([
- 'auth:sanctum',
- config('jetstream.auth_session'),
- 'verified',
-])->group(function () {
- Route::get('/dashboard', function () {
+Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified'])->group(function () {
+ Route::get('/', function () {
return Inertia::render('Dashboard');
})->name('dashboard');
-});
+
+ Route::name('superuser.')->group(function () {
+ Route::resource('permission', App\Http\Controllers\Superuser\PermissionController::class)->only([
+ 'index', 'store', 'update', 'destroy',
+ ]);
+ });
+});
\ No newline at end of file