ldc-volena/app/Http/Controllers/Fo/NewsController.php
Nicolas Demangeat 886a90f4cc wip
2024-03-13 16:05:21 +01:00

45 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\StaticPageType;
use App\Http\Controllers\Controller;
use App\Models\News;
use App\Models\Section;
use App\Models\StaticPage;
class NewsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function index(): \Illuminate\Contracts\View\View
{
$staticPageModel = StaticPage::query()->where('type', StaticPageType::we_move)->first();
$sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get();
$newsModels = News::query()->where('published', true)
->orderBy('publish_at', 'DESC')
->limit(24)
->paginate(3);
return view('fo.pages.news.index', \compact('staticPageModel', 'sectionModels', 'newsModels'));
}
/**
* Display a news articles
*
* @param string $slug
* @return \Illuminate\Contracts\View\View
*/
public function show(string $slug): \Illuminate\Contracts\View\View
{
/** @var \App\Models\News $newsModel */
$newsModel = News::query()
->where('published', true)
->where('slug', $slug)
->firstOrFail();
return view('fo.pages.news.show', \compact('newsModel'));
}
}