<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Composers\Testovanie;

use Illuminate\View\View;
use Seka\Vzdelavanie\Models\Testovanie\Test;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
 * Class ZoznamTestovPodlaPopularnostiCompose
 *
 * @package Seka\Vzdelavanie\Composers\Testovanie
 */
final class ZoznamTestovPodlaPopularnostiCompose
{
    /**
     * @param \Illuminate\View\View $view
     *
     * @return \Illuminate\View\View
     */
    public function compose(View $view): View
    {
        return $view->with(
            'testy',
            Test::withCount('popularita')
                ->publikovany()
                ->has('popularita', '>', 0)
                ->orderByDesc('popularita_count')
                ->limit(3)
                ->get()
        );
    }
}
