fix template
parent
ff16a62718
commit
63200efb88
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Role::query();
|
||||
|
||||
if ($request->q) {
|
||||
$query->where('name', 'like', "%{$request->q}%");
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GeneralController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return inertia('Dashboard');
|
||||
}
|
||||
|
||||
public function maintance()
|
||||
{
|
||||
return inertia('Maintance');
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\RolePermission;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Response;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$request->user()->allow('view-role', true);
|
||||
|
||||
$query = Role::query();
|
||||
|
||||
if ($request->q) {
|
||||
$query->where('name', 'like', "%{$request->q}%");
|
||||
}
|
||||
|
||||
$query->orderBy('created_at', 'desc');
|
||||
|
||||
return inertia('Role/Index', [
|
||||
'data' => $query->paginate(10),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return inertia('Role/Form', [
|
||||
'permissions' => Permission::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'string|required|max:255',
|
||||
'permissions' => 'array|required',
|
||||
'permissions.*.id' => 'uuid|required|exists:permissions,id',
|
||||
]);
|
||||
|
||||
DB::beginTransaction();
|
||||
$role = Role::create(['name' => $request->name]);
|
||||
foreach ($request->permissions as $permission) {
|
||||
RolePermission::create([
|
||||
'role_id' => $role->id,
|
||||
'permission_id' => $permission['id'],
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('roles.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed saved']);
|
||||
}
|
||||
|
||||
public function edit(Role $role): Response
|
||||
{
|
||||
return inertia('Role/Form', [
|
||||
'role' => $role->load(['permissions']),
|
||||
'permissions' => Permission::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Role $role): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'string|required|max:255',
|
||||
'permissions' => 'array|required',
|
||||
'permissions.*.id' => 'uuid|required|exists:permissions,id',
|
||||
]);
|
||||
|
||||
if ($role->flag == 1) {
|
||||
return redirect()->route('roles.index')
|
||||
->with('message', ['type' => 'error', 'message' => 'Item default can\'t updated']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$role->update([
|
||||
'name' => $request->name,
|
||||
]);
|
||||
|
||||
RolePermission::where('role_id', $role->id)->delete();
|
||||
|
||||
foreach ($request->permissions as $permission) {
|
||||
RolePermission::create([
|
||||
'role_id' => $role->id,
|
||||
'permission_id' => $permission['id'],
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return redirect()->route('roles.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
|
||||
}
|
||||
|
||||
public function destroy(Role $role): RedirectResponse
|
||||
{
|
||||
$deleted = $role->delete();
|
||||
|
||||
if ($deleted) {
|
||||
return redirect()->route('roles.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
|
||||
}
|
||||
|
||||
return redirect()->route('roles.index')
|
||||
->with('message', ['type' => 'error', 'message' => 'Item default can\'t deleted']);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Response;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = User::query()->with(['role']);
|
||||
|
||||
if ($request->q) {
|
||||
$query->where('name', 'like', "%{$request->q}%");
|
||||
}
|
||||
|
||||
$query->orderBy('created_at', 'desc');
|
||||
|
||||
return inertia('User/Index', [
|
||||
'data' => $query->paginate(10),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'password' => 'required|string|max:255',
|
||||
'role_id' => 'required|uuid|exists:roles,id',
|
||||
]);
|
||||
|
||||
User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => bcrypt($request->password),
|
||||
'role_id' => $request->role_id,
|
||||
]);
|
||||
|
||||
return redirect()->route('user.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed saved']);
|
||||
}
|
||||
|
||||
public function update(Request $request, User $user): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email' => 'required|email|unique:users,email,'.$user->id,
|
||||
'password' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
if ($user->role != null) {
|
||||
$request->validate([
|
||||
'role_id' => 'required|uuid|exists:roles,id',
|
||||
]);
|
||||
}
|
||||
|
||||
$user->fill([
|
||||
'email' => $request->email,
|
||||
'name' => $request->name,
|
||||
'role_id' => $request->role_id,
|
||||
]);
|
||||
|
||||
if ($request->password != '') {
|
||||
$user->password = bcrypt($request->password);
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
return redirect()->route('user.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
|
||||
}
|
||||
|
||||
public function destroy(User $user): RedirectResponse
|
||||
{
|
||||
if ($user->role_id == null) {
|
||||
return redirect()->route('user.index')
|
||||
->with('message', ['type' => 'error', 'message' => 'Item default can\'t deleted']);
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
return redirect()->route('user.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head } from '@inertiajs/react';
|
||||
import { HiFire } from 'react-icons/hi';
|
||||
|
||||
export default function Maintance(props) {
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
auth={props.auth}
|
||||
errors={props.errors}
|
||||
flash={props.flash}
|
||||
page={"Page"}
|
||||
action={"Development Mode"}
|
||||
>
|
||||
<Head title="Masih Dalam Pengembangan" />
|
||||
|
||||
<div>
|
||||
<div className="mx-auto sm:px-6 lg:px-8 text-center">
|
||||
<div className="overflow-hidden py-40 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex justify-center items-center flex-col">
|
||||
<HiFire className='text-center dark:text-white w-40 h-40'/>
|
||||
<div className="p-6 dark:text-gray-100 text-3xl">Fitur Dalam Pengembangan</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue