create user crud
This commit is contained in:
205
app/Http/Controllers/Superuser/UserController.php
Normal file
205
app/Http/Controllers/Superuser/UserController.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Superuser/User/Index')->with([
|
||||
'roles' => Role::get(),
|
||||
'permissions' => Permission::get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function paginate(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'search' => 'nullable|string',
|
||||
'per_page' => 'nullable|integer|max:1000',
|
||||
'order.key' => 'nullable|string',
|
||||
'order.dir' => 'nullable|in:asc,desc',
|
||||
]);
|
||||
|
||||
return User::where(function (Builder $query) use ($request) {
|
||||
$search = '%' . $request->input('search') . '%';
|
||||
$columns = ['name', 'username', 'email', 'email_verified_at', 'created_at', 'updated_at'];
|
||||
|
||||
foreach ($columns as $column)
|
||||
$query->orWhere($column, 'like', $search);
|
||||
|
||||
$query->orWhereRelation('permissions', 'name', 'like', $search);
|
||||
$query->orWhereRelation('roles', 'name', 'like', $search);
|
||||
})
|
||||
->orderBy($request->input('order.key') ?: 'name', $request->input('order.dir') ?: 'asc')
|
||||
->with(['permissions', 'roles'])
|
||||
->paginate($request->per_page ?: 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$post = $request->validate([
|
||||
'name' => 'required|string',
|
||||
'username' => 'required|string|unique:users',
|
||||
'email' => 'required|email|unique:users',
|
||||
'password' => 'required|string|min:8',
|
||||
'password_confirmation' => 'required|same:password',
|
||||
'roles.*' => 'nullable|integer|exists:roles,id',
|
||||
'permissions.*' => 'nullable|integer|exists:permissions,id',
|
||||
]);
|
||||
|
||||
$post['password'] = Hash::make($post['password']);
|
||||
|
||||
if ($user = User::create($post)) {
|
||||
$user->permissions()->sync($request->input('permissions', []));
|
||||
$user->roles()->sync($request->input('roles', []));
|
||||
$user->email_verified_at = now();
|
||||
$user->save();
|
||||
|
||||
return redirect()->back()->with('success', __(
|
||||
'user `:name` has been created', [
|
||||
'name' => $user->name,
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __(
|
||||
'can\'t create user'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, User $user)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string'],
|
||||
'username' => ['required', 'string', Rule::unique('users')->ignore($user->id)],
|
||||
'email' => ['required', 'email', Rule::unique('users')->ignore($user->id)],
|
||||
'password' => ['nullable', 'string', 'min:8'],
|
||||
'password_confirmation' => ['nullable', 'same:password'],
|
||||
'roles.*' => ['nullable', 'integer', 'exists:roles,id'],
|
||||
'permissions.*' => ['nullable', 'integer', 'exists:permissions,id'],
|
||||
]);
|
||||
|
||||
if ($user->update($request->only(['name', 'username', 'email']))) {
|
||||
$user->permissions()->sync($request->input('permissions', []));
|
||||
$user->roles()->sync($request->input('roles', []));
|
||||
|
||||
if ($password = $request->input('password')) {
|
||||
$user->update([
|
||||
'password' => Hash::make($password),
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', __(
|
||||
'user `:name` has been updated', [
|
||||
'name' => $user->name,
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __(
|
||||
'can\'t update user'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(User $user)
|
||||
{
|
||||
if ($user->delete()) {
|
||||
return redirect()->back()->with('success', __(
|
||||
'user `:name` has been deleted', [
|
||||
'name' => $user->name,
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __(
|
||||
'can\'t delete user'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Permission $permission
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function detachPermission(User $user, Permission $permission)
|
||||
{
|
||||
if ($user->permissions()->detach([$permission->id])) {
|
||||
return redirect()->back()->with('success', __(
|
||||
'permission `:permission from user `:user` has been detached`', [
|
||||
'permission' => $permission->name,
|
||||
'user' => $user->name,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __(
|
||||
'can\'t detach permission `:permission` from user `:user`', [
|
||||
'permission' => $permission->name,
|
||||
'user' => $user->name,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Role $role
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function detachRole(User $user, Role $role)
|
||||
{
|
||||
if ($user->roles()->detach([$role->id])) {
|
||||
return redirect()->back()->with('success', __(
|
||||
'role `:role from user `:user` has been detached`', [
|
||||
'role' => $role->name,
|
||||
'user' => $user->name,
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __(
|
||||
'can\'t detach role `:role` from user `:user`', [
|
||||
'role' => $role->name,
|
||||
'user' => $user->name,
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
337
resources/js/Pages/Superuser/User/Index.vue
Normal file
337
resources/js/Pages/Superuser/User/Index.vue
Normal file
@@ -0,0 +1,337 @@
|
||||
<script setup>
|
||||
import { getCurrentInstance, nextTick, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { Inertia } from '@inertiajs/inertia'
|
||||
import { useForm } from '@inertiajs/inertia-vue3'
|
||||
import DashboardLayout from '@/Layouts/DashboardLayout.vue'
|
||||
import Card from '@/Components/Card.vue'
|
||||
import Icon from '@/Components/Icon.vue'
|
||||
import Builder from '@/Components/DataTable/Builder.vue'
|
||||
import Th from '@/Components/DataTable/Th.vue'
|
||||
import Swal from 'sweetalert2'
|
||||
import Select from '@vueform/multiselect'
|
||||
|
||||
const self = getCurrentInstance()
|
||||
const { permissions, roles } = defineProps({
|
||||
permissions: Array,
|
||||
roles: Array,
|
||||
})
|
||||
const form = useForm({
|
||||
id: null,
|
||||
name: '',
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
password_confirmation: '',
|
||||
permissions: [],
|
||||
roles: [],
|
||||
})
|
||||
|
||||
const tableRefresh = ref(null)
|
||||
const open = ref(false)
|
||||
|
||||
const show = () => {
|
||||
open.value = true
|
||||
nextTick(() => self.refs.name?.focus())
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
open.value = false
|
||||
form.reset()
|
||||
form.clearErrors()
|
||||
tableRefresh.value && tableRefresh.value()
|
||||
}
|
||||
|
||||
const store = () => {
|
||||
return form.post(route('superuser.user.store'), {
|
||||
onSuccess: () => close() || (tableRefresh.value && tableRefresh.value()),
|
||||
onError: () => show(),
|
||||
})
|
||||
}
|
||||
|
||||
const edit = user => {
|
||||
form.id = user.id
|
||||
form.name = user.name
|
||||
form.username = user.username
|
||||
form.email = user.email
|
||||
form.permissions = user.permissions.map(permission => permission.id)
|
||||
form.roles = user.roles.map(role => role.id)
|
||||
|
||||
show()
|
||||
}
|
||||
|
||||
const update = () => {
|
||||
return form.patch(route('superuser.user.update', form.id), {
|
||||
onSuccess: () => close() || (tableRefresh.value && tableRefresh.value()),
|
||||
onError: () => show(),
|
||||
})
|
||||
}
|
||||
|
||||
const destroy = async (user, refresh) => {
|
||||
const response = await Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'You can\'t restore it after deleted',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
showCloseButton: true,
|
||||
})
|
||||
|
||||
if (response.isConfirmed) {
|
||||
Inertia.on('finish', () => refresh())
|
||||
|
||||
return Inertia.delete(route('superuser.user.destroy', user.id))
|
||||
}
|
||||
}
|
||||
|
||||
const submit = () => form.id ? update() : store()
|
||||
|
||||
const detachPermission = async (user, permission, refresh) => {
|
||||
const response = await Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'You can re adding it on edit page',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
showCloseButton: true,
|
||||
})
|
||||
|
||||
if (!response.isConfirmed)
|
||||
return
|
||||
|
||||
Inertia.on('finish', () => refresh())
|
||||
Inertia.patch(route('superuser.user.permission.detach', { user: user.id, permission: permission.id }))
|
||||
}
|
||||
|
||||
const detachRole = async (user, role, refresh) => {
|
||||
const response = await Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'You can re adding it on edit page',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
showCloseButton: true,
|
||||
})
|
||||
|
||||
if (!response.isConfirmed)
|
||||
return
|
||||
|
||||
Inertia.on('finish', () => refresh())
|
||||
Inertia.patch(route('superuser.user.role.detach', { user: user.id, role: role.id }))
|
||||
}
|
||||
|
||||
const esc = e => e.key === 'Escape' && close()
|
||||
onMounted(() => window.addEventListener('keydown', esc))
|
||||
onUnmounted(() => window.removeEventListener('keydown', esc))
|
||||
</script>
|
||||
|
||||
<style src="@vueform/multiselect/themes/default.css"></style>
|
||||
|
||||
<template>
|
||||
<DashboardLayout title="user">
|
||||
<Card class="dark:bg-gray-700 dark:text-gray-100">
|
||||
<template #header>
|
||||
<div class="flex items-center space-x-2 p-2 dark:bg-gray-800">
|
||||
<button v-if="can('create user')" @click.prevent="show" class="bg-green-600 hover:bg-green-700 rounded-md px-3 py-1 text-sm transition-all">
|
||||
<div class="flex items-center space-x-1">
|
||||
<Icon name="plus" />
|
||||
<p class="uppercase font-semibold">create</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #body>
|
||||
<div class="flex flex-col space-y-2">
|
||||
<Builder :url="route('api.v1.superuser.user.paginate')">
|
||||
<template v-slot:thead="table">
|
||||
<tr>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center" :table="table" :sort="false">no</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="name">name</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="username">username</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="email">email</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">permissions</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">roles</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="email_verified_at">verified at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="created_at">created at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="true" name="updated_at">updated at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">action</Th>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
<template v-slot:tfoot="table">
|
||||
<tr>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center" :table="table" :sort="false">no</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">name</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">username</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">email</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">permissions</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">roles</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">verified at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">created at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">updated at</Th>
|
||||
<Th class="dark:bg-gray-800 border dark:border-gray-900 px-3 py-2 text-center whitespace-nowrap" :table="table" :sort="false">action</Th>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
<template v-slot:tbody="{ data, refresh }">
|
||||
<tr v-for="(user, i) in (tableRefresh = refresh) ? data : data" :key="i">
|
||||
<td class="px-2 py-1 border dark:border-gray-800 text-center">{{ i + 1 }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ user.name }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ user.username }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ user.email }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800">
|
||||
<div class="flex-wrap">
|
||||
<div v-for="(permission, j) in user.permissions" :key="j" class="inline-block bg-gray-600 rounded-md px-3 py-1 m-[1px] text-sm">
|
||||
<div class="flex items-center justify-between space-x-1">
|
||||
<p class="uppercase font-semibold">{{ permission.name }}</p>
|
||||
|
||||
<Icon @click.prevent="detachPermission(user, permission, refresh)" v-if="can('update user')" name="times" class="px-2 py-1 rounded-md dark:bg-gray-700 transition-all hover:bg-red-500 cursor-pointer" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800">
|
||||
<div class="flex-wrap">
|
||||
<div v-for="(role, j) in user.roles" :key="j" class="inline-block bg-gray-600 rounded-md px-3 py-1 m-[1px] text-sm">
|
||||
<div class="flex items-center justify-between space-x-1">
|
||||
<p class="uppercase font-semibold">{{ role.name }}</p>
|
||||
|
||||
<Icon @click.prevent="detachRole(user, role, refresh)" v-if="can('update user')" name="times" class="px-2 py-1 rounded-md dark:bg-gray-700 transition-all hover:bg-red-500 cursor-pointer" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ new Date(user.email_verified_at).toLocaleString('id') }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ new Date(user.created_at).toLocaleString('id') }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800 uppercase">{{ new Date(user.updated_at).toLocaleString('id') }}</td>
|
||||
<td class="px-2 py-1 border dark:border-gray-800">
|
||||
<div class="flex items-center space-x-2">
|
||||
<button @click.prevent="edit(user, refresh)" class="bg-blue-600 rounded-md px-3 py-1 transition-all hover:bg-blue-700 text-white text-sm">
|
||||
<div class="flex items-center space-x-2">
|
||||
<Icon name="edit" />
|
||||
<p class="uppercase">edit</p>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button @click.prevent="destroy(user, refresh)" class="bg-red-600 rounded-md px-3 py-1 transition-all hover:bg-red-700 text-white text-sm">
|
||||
<div class="flex items-center space-x-2">
|
||||
<Icon name="trash" />
|
||||
<p class="uppercase">delete</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
</Builder>
|
||||
</div>
|
||||
</template>
|
||||
</Card>
|
||||
</DashboardLayout>
|
||||
|
||||
<transition name="fade">
|
||||
<div v-if="open" class="fixed top-0 left-0 w-full h-full bg-black bg-opacity-25 flex items-center justify-center">
|
||||
<form @submit.prevent="submit" class="w-full max-w-xl shadow-xl">
|
||||
<Card class="dark:bg-gray-700 dark:text-gray-100">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-end bg-gray-800 p-2">
|
||||
<Icon @click.prevent="close" name="times" class="px-2 py-1 dark:bg-gray-700 dark:hover:bg-gray-600 rounded-md transition-all cursor-pointer" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #body>
|
||||
<div class="flex flex-col space-y-4 p-2">
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="name" class="w-1/3 lowercase first-letter:capitalize">name</label>
|
||||
<input ref="name" type="text" name="name" v-model="form.name" class="w-full bg-transparent rounded-md px-3 py-1 placeholder:capitalize" placeholder="name" required>
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.name" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.name }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="username" class="w-1/3 lowercase first-letter:capitalize">username</label>
|
||||
<input ref="username" type="text" name="username" v-model="form.username" class="w-full bg-transparent rounded-md px-3 py-1 placeholder:capitalize" placeholder="username" required>
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.username" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.username }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="email" class="w-1/3 lowercase first-letter:capitalize">email</label>
|
||||
<input ref="email" type="email" name="email" v-model="form.email" class="w-full bg-transparent rounded-md px-3 py-1 placeholder:capitalize" placeholder="email" required>
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.email" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.email }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="password" class="w-1/3 lowercase first-letter:capitalize">password</label>
|
||||
<input ref="password" type="password" name="password" v-model="form.password" class="w-full bg-transparent rounded-md px-3 py-1 placeholder:capitalize" placeholder="password" :required="form.id === null">
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.password" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.password }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="password_confirmation" class="w-1/3 lowercase first-letter:capitalize">password confirmation</label>
|
||||
<input ref="password_confirmation" type="password" name="password_confirmation" v-model="form.password_confirmation" class="w-full bg-transparent rounded-md px-3 py-1 placeholder:capitalize" placeholder="password confirmation" :required="form.id === null">
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.password_confirmation" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.password_confirmation }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="permissions" class="w-1/3 lowercase first-letter:capitalize">permissions</label>
|
||||
<Select
|
||||
v-model="form.permissions"
|
||||
:options="permissions.map(p => ({
|
||||
label: p.name,
|
||||
value: p.id,
|
||||
}))"
|
||||
:searchable="true"
|
||||
class="text-gray-800 uppercase"
|
||||
mode="tags" />
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.permissions" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.permissions }}</p>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col space-y-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<label for="roles" class="w-1/3 lowercase first-letter:capitalize">roles</label>
|
||||
<Select
|
||||
v-model="form.roles"
|
||||
:options="roles.map(r => ({
|
||||
label: r.name,
|
||||
value: r.id,
|
||||
}))"
|
||||
:searchable="true"
|
||||
class="text-gray-800 uppercase"
|
||||
mode="tags" />
|
||||
</div>
|
||||
|
||||
<p v-if="form.errors.roles" class="text-red-500 text-right lowercase first-letter:capitalize">{{ form.errors.roles }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex items-center justify-end space-x-2 dark:bg-gray-800 px-2 py-1">
|
||||
<button type="submit" class="bg-green-600 rounded-md px-3 py-1 text-sm">
|
||||
<div class="flex items-center space-x-1">
|
||||
<Icon name="check" />
|
||||
|
||||
<p class="uppercase font-semibold">{{ form.id ? 'update' : 'create' }}</p>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</Card>
|
||||
</form>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
@@ -21,5 +21,6 @@ Route::prefix('/v1')->name('api.v1.')->group(function () {
|
||||
Route::get('/superuser/permission', [App\Http\Controllers\Superuser\PermissionController::class, 'get'])->name('permission');
|
||||
Route::get('/superuser/role', [App\Http\Controllers\Superuser\RoleController::class, 'get'])->name('role');
|
||||
Route::post('/superuser/role/paginate', [App\Http\Controllers\Superuser\RoleController::class, 'paginate'])->name('role.paginate');
|
||||
Route::post('/superuser/user/paginate', [App\Http\Controllers\Superuser\UserController::class, 'paginate'])->name('user.paginate');
|
||||
});
|
||||
});
|
||||
@@ -30,5 +30,12 @@ Route::middleware(['auth:sanctum', config('jetstream.auth_session'), 'verified']
|
||||
]);
|
||||
|
||||
Route::patch('/role/{role}/detach/{permission}', [App\Http\Controllers\Superuser\RoleController::class, 'detach'])->name('role.detach');
|
||||
|
||||
Route::resource('user', App\Http\Controllers\Superuser\UserController::class)->only([
|
||||
'index', 'store', 'update', 'destroy',
|
||||
]);
|
||||
|
||||
Route::patch('/user/{user}/role/{role}/detach', [App\Http\Controllers\Superuser\UserController::class, 'detachRole'])->name('user.role.detach');
|
||||
Route::patch('/user/{user}/permission/{permission}/detach', [App\Http\Controllers\Superuser\UserController::class, 'detachPermission'])->name('user.permission.detach');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user