Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.0 KiB

11 months ago
<?php
namespace App\Http\Controllers;
use App\Models\m_role;
11 months ago
use Illuminate\Http\Request;
11 months ago
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\ValidasiCreateRole;
use App\Http\Requests\ValidasiUpdateRole;
11 months ago
class RoleController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
11 months ago
$data = [
'role' => m_role::orderBy('created_at', 'desc')->get(),
11 months ago
'active' => 'menu-role',
];
return view('dashboard.Master_Data.Role.index', $data);
11 months ago
}
/**
* Show the form for creating a new resource.
*/
// public function create()
// {
// return view('MasterData.role.create');
// }
11 months ago
/**
* Store a newly created resource in storage.
*/
public function store(ValidasiCreateRole $request)
11 months ago
{
try {
11 months ago
$currentUser = Auth::user();
$validatedData = $request->except('_token');
11 months ago
$validatedData['created_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai created_by
$validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by
m_role::create($validatedData);
return redirect()->back()->with('success', 'Data role Berhasil Ditambah.');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data role Gagal Ditambah.');
}
11 months ago
}
/**
* Display the specified resource.
*/
// public function show($id)
// {
// // dd('oke');
// return view('MasterData.role.show');
// }
11 months ago
/**
* Show the form for editing the specified resource.
*/
11 months ago
// public function edit($id)
// {
// // dd('oke');
// $role = m_role::find($id);
// return view('dashboard.Master_Data.Role.edit', compact('role'));
// }
11 months ago
/**
* Update the specified resource in storage.
*/
public function update(ValidasiUpdateRole $request, $id)
11 months ago
{
try {
$currentUser = Auth::user();
$role = m_role::findOrFail($id); // Cari peran berdasarkan ID
$validatedData = $request->except('_token');
$validatedData['updated_by'] = $currentUser->fullname; // Menggunakan nama pengguna sebagai updated_by
$role->update($validatedData); // Update data peran
return redirect()->back()->with('success', 'Data role Berhasil Diperbarui.');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data role Gagal Diperbarui.');
}
11 months ago
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
// dd("oke");
try {
$role = m_role::findOrFail($id);
$role->delete();
return redirect()->back()->with('success', 'Data role berhasil dihapus');
} catch (\Throwable $th) {
return redirect()->back()->with('error', 'Data role gagal dihapus');
}
11 months ago
}
}