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