File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Magazines/MagazineController.php
<?php
namespace App\KommaApp\Magazines;
use App\Http\Controllers\Controller;
use App\KommaApp\Magazines\Models\Magazine;
use App\KommaApp\Pages\Models\Page;
class MagazineController extends Controller
{
private $magazinePrefix = 'pages.magazines.';
private $magazineService;
public function __construct(MagazineService $magazineService)
{
parent::__construct();
$this->magazineService = $magazineService;
\View::share('onMagazine', true);
}
/**
* Index redirects to the latest magazine
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function index(){
return redirect('/' . $this->links->magazine->route . '/' . $this->magazineService->getLatestMagazineAlias() );
}
public function overview(Page $page){
$magazines = $this->magazineService->getMagazines(true);
$magazines->withPath('/' . $this->links->magazineHistory->route);
\View::share('onMagazine', false);
// Return view
return \View::make($view = $this->baseViewPath.$this->magazinePrefix. 'index',[
'magazines' => $magazines,
'page' => $page,
]);
}
/**
* @param Magazine $magazine
* @return \Illuminate\Contracts\View\View
*/
public function show(Magazine $magazine)
{
// Load translation by eager loading
$magazine->load( ['translation', 'translations']);
$magazineRoute = $this->links->magazine->route.'/'.$magazine->translation->slug;
\View::share('magazineRoute', $magazineRoute);
// Get the route in other languages for menu and meta data
$otherLanguageRoutes = $this->magazineService->getLanguageRoutes($magazine);
$highlightedArticle = $this->magazineService->getCoverMagazineArticle($magazine);
// Get the articles of this magazine (to keep controller clean we put it in an other function instead of through the relation)
if(isset($highlightedArticle)) $articles = $this->magazineService->getMagazineArticles($magazine, [$highlightedArticle->id]);
else $articles = $this->magazineService->getMagazineArticles($magazine);
$articles->withPath('/' . $this->links->magazine->route.'/'.$magazine->translation->slug);
$paginationPage = \Input::get('page', 1);
if($paginationPage == 1) \Session::forget('magazinePage');
else \Session::put('magazinePage', $paginationPage);
// Return view
return \View::make($view = $this->baseViewPath.$this->magazinePrefix. 'show',[
'magazine' => $magazine,
'highlightedArticle' => $highlightedArticle,
'articles' => $articles,
'otherLanguages' => $otherLanguageRoutes,
]);
}
}