56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Informasi;
|
|
use Carbon\Carbon;
|
|
|
|
class BeritaController extends Controller
|
|
{
|
|
|
|
/**
|
|
* Tampilkan semua berita
|
|
*/
|
|
public function index()
|
|
{
|
|
$berita = Informasi::where('kategori_informasi', 'berita')
|
|
->orderBy('tanggal_informasi', 'desc')
|
|
->paginate(6);
|
|
|
|
return view('user.berita', compact('berita'));
|
|
}
|
|
|
|
|
|
/**
|
|
* Detail berita
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$berita = Informasi::where('kategori_informasi', 'berita')
|
|
->where('id_informasi', $id)
|
|
->firstOrFail();
|
|
$recentBerita = Informasi::where('kategori_informasi', 'berita')
|
|
->where('id_informasi', '!=', $id)
|
|
->orderBy('tanggal_informasi', 'desc')
|
|
->limit(5)
|
|
->get();
|
|
return view('user.detail-berita', compact('berita', 'recentBerita'));
|
|
}
|
|
|
|
|
|
/**
|
|
* Berita untuk hero slider
|
|
*/
|
|
public function hero()
|
|
{
|
|
$beritaHero = Informasi::where('kategori_informasi', 'berita')
|
|
->orderBy('tanggal_informasi', 'desc')
|
|
->take(3)
|
|
->get();
|
|
|
|
return view('user.index', compact('beritaHero'));
|
|
}
|
|
}
|