Fix on preview mode

This commit is contained in:
Ludovic CANDELLIER
2021-08-23 23:56:46 +02:00
parent 81fbec892c
commit 24fffce7a1
15 changed files with 289 additions and 102 deletions

View File

@@ -22,6 +22,12 @@ class Comments
return $model->html();
}
public static function getCommentsByModel($model, $model_id)
{
$class = self::getClass($model);
return self::getCommentsByClass($class, $model_id);
}
public static function getCommentsByClass($class, $id)
{
return self::getByModel(self::getModel($class, $id));
@@ -29,17 +35,17 @@ class Comments
public static function getModel($class, $id)
{
return $$class::find($id);
return $class::find($id);
}
public static function getClass($class)
public static function getClass($model)
{
return 'App\Models\\' . str_replace('.','\\', $class);
return 'App\Models\\' . str_replace('.','\\', $model);
}
public static function getByModel($model)
{
return $model ? $model->comments : false;
return $model ? $model->comments->sortByDesc('updated_at')->toArray() : false;
}
public static function storeComments($model, $comments)