165 lines
4.5 KiB
PHP
165 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web\Program;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use App\Models\Program\Framework;
|
|
use App\Models\Core\Program;
|
|
|
|
class FrameworkController extends Controller
|
|
{
|
|
public function index(Request $request): View
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$title = 'Kerangka Kerja';
|
|
|
|
$perPage = $request->query('per_page', 10);
|
|
$search = $request->query('search', '');
|
|
|
|
$framework = Framework::where('nama', 'like', "%$search%")
|
|
->paginate($perPage);
|
|
|
|
return view('program.framework.index', compact('title', 'framework'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(): View
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$program = Program::all();
|
|
|
|
return view('program.framework.add', compact('program'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
if (app()->has('SystemProgram')) {
|
|
$program = app('SystemProgram');
|
|
} else {
|
|
if ($request->has('program_id') && $request->input('program_id')) {
|
|
$programId = $request->input('program_id');
|
|
$program = Program::find($programId);
|
|
if (!$program) {
|
|
abort(400, 'Program tidak ditemukan.');
|
|
}
|
|
} else {
|
|
abort(400, 'Program tidak ditemukan.');
|
|
}
|
|
}
|
|
|
|
$validatedData = $request->validate([
|
|
'nama' => ['required','string','max:255'],
|
|
'tahun' => ['required','integer']
|
|
]);
|
|
$framework = Framework::create(
|
|
[...$validatedData,
|
|
'program_id' => $program->id,
|
|
]
|
|
);
|
|
return redirect()->route('framework.index')->with('success', 'Data berhasil ditambahkan.');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Request $request, string $id): View
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$framework = Framework::findOrFail($id);
|
|
|
|
return view('program.framework.view', compact('framework'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Request $request, string $id): View
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$framework = Framework::findOrFail($id);
|
|
$program = Program::all();
|
|
|
|
return view('program.framework.edit', compact('framework', 'program'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id): RedirectResponse
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$framework = Framework::findOrFail($id);
|
|
|
|
if (app()->has('SystemProgram')) {
|
|
$program = app('SystemProgram');
|
|
} else {
|
|
if ($request->has('program_id') && $request->input('program_id')) {
|
|
$programId = $request->input('program_id');
|
|
$program = Program::find($programId);
|
|
if (!$program) {
|
|
abort(400, 'Program tidak ditemukan.');
|
|
}
|
|
} else {
|
|
abort(400, 'Program tidak ditemukan.');
|
|
}
|
|
}
|
|
|
|
$validatedData = $request->validate([
|
|
'nama' => ['required','string','max:255'],
|
|
'tahun' => ['required','integer']
|
|
]);
|
|
|
|
$framework->update(
|
|
[...$validatedData,
|
|
'program_id' => $program->id,
|
|
]
|
|
);
|
|
|
|
return redirect()->route('framework.index')->with('success', 'Data berhasil diperbarui.');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id): RedirectResponse
|
|
{
|
|
if (!Gate::any(['super_admin', 'admin'])) {
|
|
abort(403);
|
|
}
|
|
|
|
$framework = Framework::findOrFail($id);
|
|
$framework->delete();
|
|
|
|
return redirect()->route('framework.index')->with('success', 'Data berhasil dihapus.');
|
|
}
|
|
}
|