program dan basis data ekosistem
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Ekosistem;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
use App\Models\Ekosistem\GroupBasisData;
|
||||
|
||||
class GroupBasisDataController extends Controller
|
||||
{
|
||||
public function index(Request $request): View
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
|
||||
$title = 'Program';
|
||||
|
||||
$perPage = $request->query('per_page', 10);
|
||||
$search = strtolower($request->query('search', ''));
|
||||
|
||||
$group = GroupBasisData::with('tabel')
|
||||
->whereRaw('lower(\'group\') LIKE ?', ["%$search%"])
|
||||
->paginate($perPage);
|
||||
return view('ekosistem.group-basis-data.index', compact('title', 'group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('ekosistem.group-basis-data.add');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
|
||||
$validated = $request->validate([
|
||||
'group' => ['required',
|
||||
'string',
|
||||
'regex:/^[a-z0-9]+(_[a-z0-9]+)*$/',
|
||||
'unique:ekosistem_basis_data_group,group'
|
||||
],
|
||||
'label' => ['required', 'string'],
|
||||
'urutan' => ['nullable', 'integer', 'min:1'],
|
||||
'deskripsi' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
GroupBasisData::create([...$validated,
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return redirect()->route('group.index')->with('success', 'Kelompok basis data berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id): View
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
$group = GroupBasisData::find($id);
|
||||
if (!$group) {
|
||||
return redirect()->route('group-basis-data.index')->with('error', 'Kelompok basis data tidak ditemukan.');
|
||||
}
|
||||
return view('ekosistem.group-basis-data.view', compact('group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id): View
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
|
||||
$group = GroupBasisData::find($id);
|
||||
if (!$group) {
|
||||
return redirect()->route('group-basis-data.index')->with('error', 'Kelompok basis data tidak ditemukan.');
|
||||
}
|
||||
|
||||
return view('ekosistem.group-basis-data.edit', compact('group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id): RedirectResponse
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
|
||||
$group = GroupBasisData::find($id);
|
||||
if (!$group) {
|
||||
return redirect()->route('group-basis-data.index')->with('error', 'Kelompok basis data tidak ditemukan.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'group' => ['required',
|
||||
'string',
|
||||
'regex:/^[a-z0-9]+(_[a-z0-9]+)*$/',
|
||||
'unique:ekosistem_basis_data_tabel,tabel'
|
||||
],
|
||||
'label' => ['required', 'string'],
|
||||
'urutan' => ['nullable', 'integer', 'min:1'],
|
||||
'deskripsi' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$group->update([...$validated,
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
return redirect()->route('group.index')->with('success', 'Kelompok basis data berhasil diperbarui.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
Gate::authorize('super_admin');
|
||||
|
||||
$group = TabelBasisData::find($id);
|
||||
if (!$group) {
|
||||
return redirect()->route('group.index')->with('error', 'Kelompok basis data tidak ditemukan.');
|
||||
}
|
||||
|
||||
$group->delete();
|
||||
|
||||
return redirect()->route('group.index')->with('success', 'Kelompok basis data berhasil dihapus.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user