57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\Category;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PostApprovalController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$posts = Post::with('user') // Pastikan hubungan di model Post benar
|
|
->orderByRaw("CASE WHEN status = 'pending' THEN 0 ELSE 1 END")
|
|
->orderBy('created_at', 'asc')
|
|
->get();
|
|
|
|
$categories = Category::all();
|
|
|
|
return view('admin.post-approval', [
|
|
'posts' => $posts,
|
|
'categories' => $categories
|
|
]);
|
|
}
|
|
|
|
public function approve($id)
|
|
{
|
|
$post = Post::find($id);
|
|
$post->status_published = 'active';
|
|
$post->status = 'published';
|
|
|
|
try {
|
|
$post->save();
|
|
alert()->success('Berhasil', 'Menyetujui Postingan');
|
|
return redirect()->back();
|
|
} catch (\Throwable $th) {
|
|
alert()->error('Gagal', 'Menyetujui Postingan');
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
|
|
public function reject($id)
|
|
{
|
|
$post = Post::find($id);
|
|
$post->status = 'rejected';
|
|
|
|
try {
|
|
$post->save();
|
|
alert()->success('Berhasil', 'Menolak Postingan');
|
|
return redirect()->back();
|
|
} catch (\Throwable $th) {
|
|
alert()->error('Gagal', 'Menolak Postingan');
|
|
return redirect()->back();
|
|
}
|
|
}
|
|
}
|