Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/syn.corals.io/Corals/modules/Utility/Classes/Comment/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/syn.corals.io/Corals/modules/Utility/Classes/Comment/CommentManager.php
<?php

namespace Corals\Modules\Utility\Classes\Comment;

use Corals\Modules\Utility\Models\Comment\Comment as CommentModel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class CommentManager
{

    protected $instance, $author;

    /**
     * RatingManager constructor.
     * @param $instance
     * @param $author
     */
    public function __construct($instance, $author)
    {
        $this->instance = $instance;
        $this->author = $author;
    }

    /**
     * @param $data
     * @return CommentModel|Model
     */
    public function createComment($data)
    {
        $data = array_merge([
            'commentable_id' => $this->instance->id,
            'commentable_type' => getModelMorphMap($this->instance),
        ], $data);
        if ($this->author) {
            $data = array_merge([
                'author_id' => $this->author->id,
                'author_type' => getModelMorphMap($this->author),
            ], $data);
        }
        $comment = CommentModel::create($data);


        event('notifications.comment.comment_created', [
            'comment' => $comment,
        ]);

        return $comment;
    }

    /**
     * @param CommentModel $comment
     * @return bool|null
     * @throws \Exception
     */
    public function deleteComment(CommentModel $comment)
    {
        return $comment->delete();
    }

    public static function getCommentableTypes()
    {
        return cache()->remember('getCommentableTypes', 1440, function () {
            $result = DB::table('utility_comments')
                ->distinct()
                ->select('commentable_type')
                ->get();

            $list = [];

            foreach ($result as $record) {
                if ($record->commentable_type) {
                    $list[$record->commentable_type] = basename($record->commentable_type);
                }
            }

            return $list;
        });
    }
}

Spamworldpro Mini