html(); } public static function getCommentsByClass($class, $id) { return self::getByModel(self::getModel($class, $id)); } public static function getModel($class, $id) { return $$class::find($id); } public static function getClass($class) { return 'App\Models\\' . str_replace('.','\\', $class); } public static function getByModel($model) { return $model ? $model->comments : false; } public static function storeComments($model, $comments) { foreach (($comments ?? []) as $comment) { self::storeComment($model, $comment); } } public static function storeComment($model, $comment) { return $model->comment($comment); } public static function store($data) { $id = $data['id'] ?? false; unset($data['_token']); $data['commentable_type'] = Comments::getClass($data['commentable_type']); $data['commentable_id'] = (int) $data['commentable_id']; return $id ? self::update($data, $id) : self::create($data); } public static function create($data) { unset($data['id']); $data['is_approved'] = true; $data['user_id'] = Users::getId(); return rawComment::create($data); } public static function update($data, $id = false) { $id = $id ? $id : $data['id']; $model = self::get($id); $model->update($data); return $model; } public static function deleteComments($model) { return true; } public static function deleteComment($model, $index) { return true; } }