51 lines
1.6 KiB
PHP
51 lines
1.6 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('order')->simplePaginate(4);
|
|
|
|
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(News $news): \Illuminate\Contracts\View\View
|
|
{
|
|
/** @var \App\Models\News $nextNews */
|
|
if ($news->order === News::query()->where('published', true)->max('order')) {
|
|
$nextNews = News::query()
|
|
->where('published', true)
|
|
->orderBy('order')
|
|
->firstOrFail();
|
|
} else {
|
|
$nextNews = News::query()
|
|
->where('order', '>', $news->order)
|
|
->where('published', true)
|
|
->orderBy('order')
|
|
->firstOrFail();
|
|
}
|
|
|
|
return view('fo.pages.news.show', \compact('news', 'nextNews'));
|
|
}
|
|
}
|