comments
This commit is contained in:
@@ -2,23 +2,50 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use BeyondCode\Comments\Comment;
|
||||
use App\Models\Core\Comment as rawComment;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
use App\Datatables\Admin\Core\CommentsDataTable;
|
||||
|
||||
class Comments
|
||||
{
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return rawComment::find($id);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = new CommentsDataTable();
|
||||
return $model->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)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
return $model->comments;
|
||||
return $model ? $model->comments : false;
|
||||
}
|
||||
|
||||
public static function storeComments($model, $comments)
|
||||
{
|
||||
if ($comments) {
|
||||
foreach ($comments as $comment) {
|
||||
self::storeComment($model, $comment);
|
||||
}
|
||||
foreach (($comments ?? []) as $comment) {
|
||||
self::storeComment($model, $comment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +54,31 @@ class Comments
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user