83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\ContentRecapRequest;
|
|
use App\Models\ContentRecap;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ContentRecapController extends Controller
|
|
{
|
|
public function index(){
|
|
return view('dashboard.content-recaps.index', [
|
|
'title' => 'Rekap Konten'
|
|
]);
|
|
}
|
|
|
|
public function create(){
|
|
return view('dashboard.content-recaps.create', [
|
|
'title' => 'Tambah Rekap Konten'
|
|
]);
|
|
}
|
|
|
|
public function store(ContentRecapRequest $request){
|
|
$validatedData = $request->validated();
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$createdContentRecap = ContentRecap::create($validatedData);
|
|
|
|
if($createdContentRecap){
|
|
return redirect()->back()->with('success-status', 'Berhasil menambahkan rekap konten.');
|
|
}else{
|
|
return redirect()->back()->with('failed-status', 'Gagal menambahkan rekap konten.');
|
|
}
|
|
}
|
|
|
|
public function edit($id){
|
|
$contentRecap = ContentRecap::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.content-recaps.edit', [
|
|
'title' => 'Ubah Rekap Konten',
|
|
'contentRecap' => $contentRecap
|
|
]);
|
|
}
|
|
|
|
public function update(ContentRecapRequest $request, $id){
|
|
$validatedData = $request->validated();
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$contentRecap = ContentRecap::findOrFail(decrypt_id($id));
|
|
$updatedContentRecap = $contentRecap->update($validatedData);
|
|
|
|
if($updatedContentRecap){
|
|
return redirect()->back()->with('success-status', 'Berhasil mengubah rekap konten.');
|
|
}else{
|
|
return redirect()->back()->with('failed-status', 'Gagal mengubah rekap konten.');
|
|
}
|
|
|
|
}
|
|
|
|
public function show($id){
|
|
$contentRecap = ContentRecap::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.content-recaps.show', [
|
|
'title' => 'Detail Rekap Konten',
|
|
'contentRecap' => $contentRecap
|
|
]);
|
|
}
|
|
|
|
public function destroy($id){
|
|
try {
|
|
$contentRecap = ContentRecap::findOrFail(decrypt_id($id));
|
|
|
|
$contentRecap->delete();
|
|
|
|
return response()->json(['message' => 'Berhasil menghapus rekap konten.']);
|
|
} catch (\Exception $e) {
|
|
return response()->json(['message' => 'Gagal menghapus rekap konten.'], 500);
|
|
}
|
|
}
|
|
}
|