<?php namespace App\Libs\Composers;

use App\Libs\Support\Sanitizer\Sanitizer;
use App\Models\BlogPost;
use App\Models\Lang;

class SliderPostsComposer
{

    public function compose($view)
    {
        $cats = explode(',', $view->block->blogCategory ? $view->block->blogCategory->id : '');
        $redirectPath = getCtaLink($view->block->cta1);

        $posts = BlogPost::full()
            ->with(['media', 'authors'])
            ->where('status', 'published')
            ->where('lang_status', 'published')
            ->inCategories($cats)
            ->orderBy('date', 'desc')
            ->limit(12)
            ->get();

        $view->with(array(
            'posts' => $posts,
            'redirectPath' => $redirectPath
        ));
    }
}
