You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2021. It is now read-only.
Publish configurations and migrations, then migrate comments table.
37
+
39
38
```bash
40
39
$ php artisan vendor:publish
41
40
$ php artisan migrate
42
41
```
43
42
44
43
Add `CanComment` trait to your User model.
44
+
45
45
```php
46
46
use Actuallymab\LaravelComment\CanComment;
47
47
```
48
48
49
-
Add `Commentable` trait to your commentable model(s).
49
+
Add `Commentable` interface and `HasComments` trait to your commentable model(s).
50
+
50
51
```php
51
-
use Actuallymab\LaravelComment\Commentable;
52
+
use Actuallymab\LaravelComment\Contracts\Commentable;
53
+
use Actuallymab\LaravelComment\HasComments;
54
+
55
+
class Product extends Model implements Commentable
56
+
{
57
+
use HasComments;
58
+
59
+
// ...
60
+
}
52
61
```
53
62
54
63
If you want to have your own Comment Model create a new one and extend my Comment model.
64
+
55
65
```php
56
-
class Comment extends Actuallymab\LaravelComment\Comment
66
+
use Actuallymab\LaravelComment\Models\Comment as LaravelComment;
67
+
68
+
class Comment extends LaravelComment
57
69
{
58
-
...
70
+
// ...
59
71
}
60
72
```
61
73
74
+
and dont forget to update the model name in the `config/comment.php` file.
75
+
62
76
Comment package comes with several modes.
63
77
64
-
1- If you want to Users can rate your model(s) with comment set `canBeRated` to true in your `Commentable` model.
78
+
1- If you want to users can rate your commentable models;
79
+
65
80
```php
66
-
class Product extends Model {
67
-
use Commentable;
81
+
class Product extends Model implements Commentable
82
+
{
83
+
use HasComments;
68
84
69
-
protected $canBeRated = true;
85
+
public function canBeRated(): bool
86
+
{
87
+
return true; // default false
88
+
}
70
89
71
-
...
90
+
//...
72
91
}
73
92
```
74
93
75
-
2- If you want to approve comments for your commentable models, you must set `mustBeApproved` to true in your `Commentable` model.
94
+
2- If you want to approve comments for your commentable models;
95
+
76
96
```php
77
-
class Product extends Model {
78
-
use Commentable;
97
+
class Product extends Model implements Commentable
98
+
{
99
+
use HasComments;
79
100
80
-
protected $mustBeApproved = true;
101
+
public function mustBeApproved(): bool
102
+
{
103
+
return true; // default false
104
+
}
81
105
82
-
...
106
+
// ...
83
107
}
84
108
```
85
109
86
-
3- You don't want to approve comments for all users (think this as you really want to approve your own comments?). So add your `User` model an `isAdmin` method and return it true if user is admin.
110
+
3- Sometimes you don't want to approve comments for all users;
0 commit comments