Update the README.md with the new features documentation.

This commit is contained in:
3m1n3nc3
2024-07-09 05:01:10 +01:00
parent c652a9cfe0
commit 3ddea7ece2
10 changed files with 38 additions and 52 deletions
+5 -5
View File
@@ -4,9 +4,9 @@ namespace BeyondCode\Comments;
use BeyondCode\Comments\Events\CommentAdded;
use BeyondCode\Comments\Events\CommentDeleted;
use BeyondCode\Comments\Traits\HasComments;
use Exception;
use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;
class Comment extends Model
{
@@ -15,11 +15,11 @@ class Comment extends Model
protected $fillable = [
'comment',
'user_id',
'is_approved'
'is_approved',
];
protected $casts = [
'is_approved' => 'boolean'
'is_approved' => 'boolean',
];
public static function boot(): void
@@ -80,10 +80,10 @@ class Comment extends Model
return config('comments.user_model');
}
if (!is_null(config('auth.providers.users.model'))) {
if (! is_null(config('auth.providers.users.model'))) {
return config('auth.providers.users.model');
}
throw new Exception('Could not determine the commentator model name.');
}
}
}
-1
View File
@@ -16,7 +16,6 @@ class CommentsServiceProvider extends ServiceProvider
__DIR__.'/../config/config.php' => config_path('comments.php'),
], 'config');
if (! class_exists('CreateCommentsTable')) {
$this->publishes([
__DIR__.'/../database/migrations/create_comments_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_comments_table.php'),
+3 -5
View File
@@ -2,14 +2,12 @@
namespace BeyondCode\Comments\Contracts;
interface Commentator
{
/**
* Check if a comment for a specific model needs to be approved.
* @param mixed $model
* @return bool
*
* @param mixed $model
*/
public function needsCommentApproval($model): bool;
}
}
+1 -1
View File
@@ -19,4 +19,4 @@ class CommentDeleted implements ShouldDispatchAfterCommit
public Comment $comment,
) {
}
}
}
+3 -4
View File
@@ -2,16 +2,15 @@
namespace BeyondCode\Comments\Traits;
trait CanComment
{
/**
* Check if a comment for a specific model needs to be approved.
* @param mixed $model
* @return bool
*
* @param mixed $model
*/
public function needsCommentApproval($model): bool
{
return true;
}
}
}
+3 -7
View File
@@ -2,9 +2,8 @@
namespace BeyondCode\Comments\Traits;
use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Contracts\Commentator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
trait HasComments
@@ -22,7 +21,6 @@ trait HasComments
/**
* Attach a comment to this model.
*
* @param string $comment
* @return \Illuminate\Database\Eloquent\Model
*/
public function comment(string $comment)
@@ -33,8 +31,6 @@ trait HasComments
/**
* Attach a comment to this model as a specific user.
*
* @param Model|null $user
* @param string $comment
* @return \Illuminate\Database\Eloquent\Model
*/
public function commentAsUser(?Model $user, string $comment)
@@ -43,7 +39,7 @@ trait HasComments
$comment = new $commentClass([
'comment' => $comment,
'is_approved' => ($user instanceof Commentator) ? !$user->needsCommentApproval($this) : false,
'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
'user_id' => is_null($user) ? null : $user->getKey(),
'commentable_id' => $this->getKey(),
'commentable_type' => get_class(),
@@ -51,4 +47,4 @@ trait HasComments
return $this->comments()->save($comment);
}
}
}