HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/app/ToDos/ToDoController.php
<?php

namespace App\ToDos;

use App\Base\Controller;
use App\Countries\CountryService;
use App\ToDos\Models\ToDo;
use Komma\KMS\Components\ComponentService;

final class ToDoController extends Controller
{

    public function index()
    {
        $page = $this->links->to_dos->node;

        $todos = ToDo::where('active', 1)
            ->with('translation')
            ->with('country')
            ->has('translation')
            ->has('country')
            ->orderBy('lft')
            ->paginate(6);

        $todos->withPath($this->links->to_dos->route);

        // Return view
        return view('templates.to_dos_index',[
            'links' => $this->links,
            'page' => $page,
            'todos' => $todos,
        ]);
    }

    public function show(ToDo $toDo)
    {
        $page = $this->links->to_dos->node;

        $toDo->load('translation', 'headingImage', 'sidebar', 'sidebar.translation');
        $toDo->cleanUp();

        /** @var ComponentService $componentService */
        $componentService = app(ComponentService::class);
        $components = $componentService->getViewComponents($toDo->translation);
        $sidebar = $componentService->getViewComponents($toDo->sidebar->translation);

        /** @var CountryService $countryService */
        $countryService = app()->make(CountryService::class);
        if(!empty($toDo->country_id)) $otherModels = $countryService->getSuggestions($toDo->country_id, $toDo);
        else $otherModels = collect([]);

        $toDos = ToDo::where('active', '1')
            ->with('translation', 'headingImage')
            ->take((6 - $otherModels->count()))
            ->where('id', '!=', $toDo->id)
            ->get();

        $otherModels = $otherModels->merge($toDos);

        // Return view
        return view('templates.model_show',[
            'components' => $components,
            'model' => $toDo,
            'links' => $this->links,
            'page' => $page,
            'sidebar' => $sidebar,
            'otherModels' => $otherModels
        ]);
    }
}