CommenterComposer.php 1.01 KB
<?php

namespace FootyRoom\Http\ViewComposers;

use Illuminate\View\View;

class CommenterComposer
{
    /**
     * Default options.
     *
     * @var array
     */
    protected $options = [
        'hasHeader' => true,
        'action' => '/comments',
        'allowImages' => false,
        'charsLimit' => 800,
    ];

    /**
     * Compose the view.
     *
     * @param \Illuminate\View\View $view
     * @param int $postId
     * @param object $user
     * @param array $options Options for the commenter.
     *
     * - hasHeader
     * - action
     * - allowImages
     * - allowVideos
     * - charsLimit
     *
     * @return \Illuminate\View\View
     */
    public function compose(View $view, $postId, $user, $options = [])
    {
        if (!isset($options['allowImages']) && $user) {
            $options['allowImages'] = true;
        }

        $options = (object) array_merge($this->options, $options);

        $options->postId = $postId;

        $view->with('commenter', $options);

        return $view;
    }
}