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