File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/app/Articles/ArticleController.php
<?php
namespace App\Articles;
use App\Base\Controller;
use App\Articles\Models\Article;
use App\Countries\CountryService;
use Komma\KMS\Components\ComponentService;
final class ArticleController extends Controller
{
public function index()
{
$page = $this->links->articles->node;
$articles = Article::where('active', 1)
->with('translation')
->with('country')
->has('translation')
->orderBy('lft')
->paginate(6);
$articles->withPath($this->links->articles->route);
// Return view
return view('templates.articles_index',[
'links' => $this->links,
'page' => $page,
'articles' => $articles,
]);
}
/**
* @param Article $article
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|void
* @throws \ReflectionException
*/
public function show(Article $article)
{
$page = $this->links->articles->node;
$article->load('translation', 'headingImage', 'sidebar', 'sidebar.translation');
$article->cleanUp();
/** @var ComponentService $componentService */
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($article->translation);
$sidebar = $componentService->getViewComponents($article->sidebar->translation);
/** @var CountryService $countryService */
$countryService = app()->make(CountryService::class);
if(!empty($article->country_id)) $otherModels = $countryService->getSuggestions($article->country_id, $article);
else $otherModels = collect([]);
$articles = Article::where('active', '1')
->with('translation', 'headingImage')
->take((6 - $otherModels->count()))
->where('id', '!=', $article->id)
->get();
$otherModels = $otherModels->merge($articles);
// Return view
return view('templates.model_show',[
'components' => $components,
'model' => $article,
'links' => $this->links,
'page' => $page,
'sidebar' => $sidebar,
'otherModels' => $otherModels
]);
}
}