112 lines
4.2 KiB
PHP
112 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\ContentRecapClassificationRequest;
|
|
use App\Models\ContentRecap;
|
|
use App\Models\ContentRecapClassification;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ContentRecapClassificationController extends Controller
|
|
{
|
|
public function index(){
|
|
return view('dashboard.content-recaps.classifications.index', [
|
|
'title' => "Klasifikasi Rekap Konten"
|
|
]);
|
|
}
|
|
|
|
public function create(){
|
|
return view('dashboard.content-recaps.classifications.create', [
|
|
'title' => "Tambah Klasifikasi Rekap Konten"
|
|
]);
|
|
}
|
|
|
|
public function store(ContentRecapClassificationRequest $request){
|
|
$validatedData = $request->validated();
|
|
$validatedData['slug'] = Str::slug($validatedData['name']);
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$existedData = ContentRecapClassification::withTrashed()->where('slug', $validatedData['slug'])->first();
|
|
|
|
if($existedData && filled($existedData->deleted_at)){
|
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
|
}elseif($existedData){
|
|
return redirect()->back()->with('failed-status', 'Tema dengan nama tersebut sudah ada.');
|
|
}
|
|
|
|
$createdClassification = ContentRecapClassification::create($validatedData);
|
|
|
|
if($createdClassification){
|
|
return redirect()->route('dashboard.content.recap.classifications.index')->with('success-status', 'Berhasil menambahkan klasifikasi rekap konten.');
|
|
}else{
|
|
return redirect()->back()->with('failed-status', 'Gagal menambahkan klasifikasi rekap konten.');
|
|
}
|
|
}
|
|
|
|
public function edit($id){
|
|
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.content-recaps.classifications.edit', [
|
|
'title' => "Ubah Klasifikasi Rekap Konten",
|
|
'contentRecapClassification' => $contentRecapClassification
|
|
]);
|
|
}
|
|
|
|
public function update(ContentRecapClassificationRequest $request, $id){
|
|
$validatedData = $request->validated();
|
|
$validatedData['slug'] = Str::slug($validatedData['name']);
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
|
$updatedContentRecapClassification = $contentRecapClassification->update($validatedData);
|
|
|
|
if($updatedContentRecapClassification){
|
|
return redirect()->back()->with('success-status', 'Berhasil mengubah klasifikasi rekap konten.');
|
|
}else{
|
|
return redirect()->back()->with('failed-status', 'Gagal mengubah klasifikasi rekap konten.');
|
|
}
|
|
}
|
|
|
|
public function show($id){
|
|
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.content-recaps.classifications.show', [
|
|
'title' => "Detail Klasifikasi Rekap Konten",
|
|
'contentRecapClassification' => $contentRecapClassification
|
|
]);
|
|
}
|
|
|
|
public function destroy($id){
|
|
try {
|
|
$contentRecapClassification = ContentRecapClassification::findOrFail(decrypt_id($id));
|
|
|
|
$contentRecapClassification->delete();
|
|
|
|
return response()->json(['message' => 'Berhasil menghapus klasifikasi rekap konten.']);
|
|
} catch (\Exception $e) {
|
|
return response()->json(['message' => 'Gagal menghapus klasifikasi rekap konten.'], 500);
|
|
}
|
|
}
|
|
|
|
public function restore($slug)
|
|
{
|
|
$recapContentClassification = ContentRecapClassification::withTrashed()
|
|
->where('slug', $slug)
|
|
->first();
|
|
|
|
if (!$recapContentClassification) {
|
|
return redirect()->back()->with('failed-status', 'Klasifikasi tidak ditemukan.');
|
|
}
|
|
|
|
if (filled($recapContentClassification->deleted_at)) {
|
|
$recapContentClassification->restore();
|
|
return redirect()->back()->with('success-status', 'Klasifikasi berhasil dipulihkan.');
|
|
}
|
|
|
|
return redirect()->back()->with('info-status', 'Klasifikasi sudah aktif.');
|
|
}
|
|
}
|