mirror of
https://github.com/wearepixel/laravel-comments.git
synced 2026-11-14 22:12:35 +00:00
Run Laravel Pint
This commit is contained in:
+3
-3
@@ -4,9 +4,9 @@ namespace BeyondCode\Comments;
|
|||||||
|
|
||||||
use BeyondCode\Comments\Events\CommentAdded;
|
use BeyondCode\Comments\Events\CommentAdded;
|
||||||
use BeyondCode\Comments\Events\CommentDeleted;
|
use BeyondCode\Comments\Events\CommentDeleted;
|
||||||
|
use BeyondCode\Comments\Traits\HasComments;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use BeyondCode\Comments\Traits\HasComments;
|
|
||||||
|
|
||||||
class Comment extends Model
|
class Comment extends Model
|
||||||
{
|
{
|
||||||
@@ -15,11 +15,11 @@ class Comment extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'comment',
|
'comment',
|
||||||
'user_id',
|
'user_id',
|
||||||
'is_approved'
|
'is_approved',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_approved' => 'boolean'
|
'is_approved' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function boot(): void
|
public static function boot(): void
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class CommentsServiceProvider extends ServiceProvider
|
|||||||
__DIR__.'/../config/config.php' => config_path('comments.php'),
|
__DIR__.'/../config/config.php' => config_path('comments.php'),
|
||||||
], 'config');
|
], 'config');
|
||||||
|
|
||||||
|
|
||||||
if (! class_exists('CreateCommentsTable')) {
|
if (! class_exists('CreateCommentsTable')) {
|
||||||
$this->publishes([
|
$this->publishes([
|
||||||
__DIR__.'/../database/migrations/create_comments_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_comments_table.php'),
|
__DIR__.'/../database/migrations/create_comments_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_comments_table.php'),
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace BeyondCode\Comments\Contracts;
|
namespace BeyondCode\Comments\Contracts;
|
||||||
|
|
||||||
|
|
||||||
interface Commentator
|
interface Commentator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Check if a comment for a specific model needs to be approved.
|
* Check if a comment for a specific model needs to be approved.
|
||||||
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function needsCommentApproval($model): bool;
|
public function needsCommentApproval($model): bool;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace BeyondCode\Comments\Traits;
|
namespace BeyondCode\Comments\Traits;
|
||||||
|
|
||||||
|
|
||||||
trait CanComment
|
trait CanComment
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Check if a comment for a specific model needs to be approved.
|
* Check if a comment for a specific model needs to be approved.
|
||||||
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function needsCommentApproval($model): bool
|
public function needsCommentApproval($model): bool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
namespace BeyondCode\Comments\Traits;
|
namespace BeyondCode\Comments\Traits;
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use BeyondCode\Comments\Contracts\Commentator;
|
use BeyondCode\Comments\Contracts\Commentator;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
|
|
||||||
trait HasComments
|
trait HasComments
|
||||||
@@ -22,7 +21,6 @@ trait HasComments
|
|||||||
/**
|
/**
|
||||||
* Attach a comment to this model.
|
* Attach a comment to this model.
|
||||||
*
|
*
|
||||||
* @param string $comment
|
|
||||||
* @return \Illuminate\Database\Eloquent\Model
|
* @return \Illuminate\Database\Eloquent\Model
|
||||||
*/
|
*/
|
||||||
public function comment(string $comment)
|
public function comment(string $comment)
|
||||||
@@ -33,8 +31,6 @@ trait HasComments
|
|||||||
/**
|
/**
|
||||||
* Attach a comment to this model as a specific user.
|
* Attach a comment to this model as a specific user.
|
||||||
*
|
*
|
||||||
* @param Model|null $user
|
|
||||||
* @param string $comment
|
|
||||||
* @return \Illuminate\Database\Eloquent\Model
|
* @return \Illuminate\Database\Eloquent\Model
|
||||||
*/
|
*/
|
||||||
public function commentAsUser(?Model $user, string $comment)
|
public function commentAsUser(?Model $user, string $comment)
|
||||||
|
|||||||
+13
-14
@@ -6,7 +6,6 @@ use BeyondCode\Comments\Events\CommentAdded;
|
|||||||
use BeyondCode\Comments\Events\CommentDeleted;
|
use BeyondCode\Comments\Events\CommentDeleted;
|
||||||
use BeyondCode\Comments\Tests\Models\ApprovedUser;
|
use BeyondCode\Comments\Tests\Models\ApprovedUser;
|
||||||
use BeyondCode\Comments\Tests\Models\Post;
|
use BeyondCode\Comments\Tests\Models\Post;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
use Illuminate\Foundation\Auth\User;
|
use Illuminate\Foundation\Auth\User;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ class CommentsTest extends TestCase
|
|||||||
public function users_without_commentator_interface_do_not_get_approved()
|
public function users_without_commentator_interface_do_not_get_approved()
|
||||||
{
|
{
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$post->comment('this is a comment');
|
$post->comment('this is a comment');
|
||||||
@@ -30,7 +29,7 @@ class CommentsTest extends TestCase
|
|||||||
public function models_can_store_comments()
|
public function models_can_store_comments()
|
||||||
{
|
{
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$post->comment('this is a comment');
|
$post->comment('this is a comment');
|
||||||
@@ -46,7 +45,7 @@ class CommentsTest extends TestCase
|
|||||||
public function comments_without_users_have_no_relation()
|
public function comments_without_users_have_no_relation()
|
||||||
{
|
{
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this is a comment');
|
$comment = $post->comment('this is a comment');
|
||||||
@@ -63,7 +62,7 @@ class CommentsTest extends TestCase
|
|||||||
auth()->login($user);
|
auth()->login($user);
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this is a comment');
|
$comment = $post->comment('this is a comment');
|
||||||
@@ -77,7 +76,7 @@ class CommentsTest extends TestCase
|
|||||||
$user = User::first();
|
$user = User::first();
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->commentAsUser($user, 'this is a comment');
|
$comment = $post->commentAsUser($user, 'this is a comment');
|
||||||
@@ -91,7 +90,7 @@ class CommentsTest extends TestCase
|
|||||||
$user = User::first();
|
$user = User::first();
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this is a comment');
|
$comment = $post->comment('this is a comment');
|
||||||
@@ -109,7 +108,7 @@ class CommentsTest extends TestCase
|
|||||||
$user = User::first();
|
$user = User::first();
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this is a comment');
|
$comment = $post->comment('this is a comment');
|
||||||
@@ -124,7 +123,7 @@ class CommentsTest extends TestCase
|
|||||||
$user = ApprovedUser::first();
|
$user = ApprovedUser::first();
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->commentAsUser($user, 'this is a comment');
|
$comment = $post->commentAsUser($user, 'this is a comment');
|
||||||
@@ -138,7 +137,7 @@ class CommentsTest extends TestCase
|
|||||||
$user = ApprovedUser::first();
|
$user = ApprovedUser::first();
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$post->comment('this comment is not approved');
|
$post->comment('this comment is not approved');
|
||||||
@@ -154,7 +153,7 @@ class CommentsTest extends TestCase
|
|||||||
public function comments_are_deleted_when_posts_are_deleted()
|
public function comments_are_deleted_when_posts_are_deleted()
|
||||||
{
|
{
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this comment will be deleted');
|
$comment = $post->comment('this comment will be deleted');
|
||||||
@@ -170,7 +169,7 @@ class CommentsTest extends TestCase
|
|||||||
config(['comments.delete_replies_along_comments' => true]);
|
config(['comments.delete_replies_along_comments' => true]);
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this comment will be deleted');
|
$comment = $post->comment('this comment will be deleted');
|
||||||
@@ -187,7 +186,7 @@ class CommentsTest extends TestCase
|
|||||||
Event::fake([CommentAdded::class]);
|
Event::fake([CommentAdded::class]);
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this comment is added');
|
$comment = $post->comment('this comment is added');
|
||||||
@@ -203,7 +202,7 @@ class CommentsTest extends TestCase
|
|||||||
Event::fake([CommentDeleted::class]);
|
Event::fake([CommentDeleted::class]);
|
||||||
|
|
||||||
$post = Post::create([
|
$post = Post::create([
|
||||||
'title' => 'Some post'
|
'title' => 'Some post',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$comment = $post->comment('this comment is added');
|
$comment = $post->comment('this comment is added');
|
||||||
|
|||||||
@@ -2,22 +2,20 @@
|
|||||||
|
|
||||||
namespace BeyondCode\Comments\Tests\Models;
|
namespace BeyondCode\Comments\Tests\Models;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\User;
|
|
||||||
use BeyondCode\Comments\Contracts\Commentator;
|
use BeyondCode\Comments\Contracts\Commentator;
|
||||||
|
use Illuminate\Foundation\Auth\User;
|
||||||
|
|
||||||
class ApprovedUser extends User implements Commentator
|
class ApprovedUser extends User implements Commentator
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $table = 'users';
|
protected $table = 'users';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a comment for a specific model needs to be approved.
|
* Check if a comment for a specific model needs to be approved.
|
||||||
|
*
|
||||||
* @param mixed $model
|
* @param mixed $model
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function needsCommentApproval($model): bool
|
public function needsCommentApproval($model): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace BeyondCode\Comments\Tests\Models;
|
namespace BeyondCode\Comments\Tests\Models;
|
||||||
|
|
||||||
use BeyondCode\Comments\Traits\HasComments;
|
use BeyondCode\Comments\Traits\HasComments;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Post extends Model
|
class Post extends Model
|
||||||
|
|||||||
+3
-5
@@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
namespace BeyondCode\Comments\Tests;
|
namespace BeyondCode\Comments\Tests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\User;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use BeyondCode\Comments\CommentsServiceProvider;
|
use BeyondCode\Comments\CommentsServiceProvider;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Foundation\Auth\User;
|
||||||
|
|
||||||
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -54,8 +53,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
|||||||
User::forceCreate([
|
User::forceCreate([
|
||||||
'name' => 'User',
|
'name' => 'User',
|
||||||
'email' => 'user@email.com',
|
'email' => 'user@email.com',
|
||||||
'password' => 'test'
|
'password' => 'test',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user