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