Skip to content

Commit 7a7e44f

Browse files
committed
Added comment and forum thread
1 parent f8bb4c2 commit 7a7e44f

File tree

19 files changed

+622
-52
lines changed

19 files changed

+622
-52
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ npm-debug.log
1515
yarn-error.log
1616
/.idea
1717
/.vscode
18+
19+
**/caddy
20+
frankenphp
21+
frankenphp-worker.php

app/Grid/Admin/CategoryItemGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function columns()
8787
},
8888
'list' => false,
8989
],
90-
include 'includes/tags.php',
90+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
9191
[
9292
'attribute' => 'created_at',
9393
'sortable' => true,

app/Grid/Admin/CategoryTypeGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function columns()
8888
];
8989
},
9090
],
91-
include 'includes/tags.php',
91+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
9292
[
9393
'attribute' => 'created_at',
9494
'sortable' => true,

app/Grid/Admin/CommentGrid.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
3+
namespace App\Grid\Admin;
4+
5+
use BalajiDharma\LaravelComment\Models\Comment;
6+
use BalajiDharma\LaravelCrud\CrudBuilder;
7+
use Config;
8+
9+
class CommentGrid extends CrudBuilder
10+
{
11+
public $title = 'Comments';
12+
13+
public $description = 'Manage Comments';
14+
15+
public $model = Comment::class;
16+
17+
public $route = 'admin.comment';
18+
19+
public function columns()
20+
{
21+
return [
22+
[
23+
'attribute' => 'id',
24+
'label' => __('ID'),
25+
'sortable' => true,
26+
'searchable' => true,
27+
'list' => [
28+
'class' => 'BalajiDharma\LaravelCrud\Column\LinkColumn',
29+
'route' => 'admin.comment.show',
30+
'route_params' => ['comment' => 'id'],
31+
'attr' => ['class' => 'link link-primary'],
32+
],
33+
],
34+
[
35+
'attribute' => 'content',
36+
'label' => __('Content'),
37+
'searchable' => true,
38+
'list' => [
39+
'class' => 'BalajiDharma\LaravelCrud\Column\LinkColumn',
40+
'route' => 'admin.comment.show',
41+
'route_params' => ['comment' => 'id'],
42+
'attr' => ['class' => 'link link-primary'],
43+
],
44+
'form_options' => function ($model) {
45+
return [
46+
'field_type' => 'textarea',
47+
'attr' => [
48+
'rows' => 5
49+
]
50+
];
51+
},
52+
],
53+
[
54+
'attribute' => 'commenter_type',
55+
'label' => __('Commenter Type'),
56+
'type' => 'select',
57+
'list' => true,
58+
'show' => true,
59+
'form_options' => function ($model) {
60+
$commenter_type = [
61+
'App\Models\User' => __('User'),
62+
];
63+
64+
return [
65+
'choices' => $commenter_type,
66+
'empty_value' => __('Select an option'),
67+
'default_value' => $model ? $model->commenter_type : null,
68+
];
69+
},
70+
],
71+
[
72+
'attribute' => 'commenter_id',
73+
'label' => __('Commenter ID'),
74+
'list' => false,
75+
'show' => false,
76+
],
77+
[
78+
'attribute' => 'commenter',
79+
'label' => __('Commenter'),
80+
'value' => function ($model) {
81+
return $model->commenter ? $model->commenter->name : null;
82+
},
83+
'create' => false,
84+
'edit' => false,
85+
'sortable' => true,
86+
],
87+
[
88+
'attribute' => 'commentable_type',
89+
'label' => __('Commentable Type'),
90+
'type' => 'select',
91+
'list' => false,
92+
'form_options' => function ($model) {
93+
$commentable_type = [
94+
'Balajidharma\LaravelForum\Models\Thread' => __('Thread'),
95+
];
96+
97+
return [
98+
'choices' => $commentable_type,
99+
'empty_value' => __('Select an option'),
100+
'default_value' => $model ? $model->commentable_type : null,
101+
];
102+
},
103+
],
104+
[
105+
'attribute' => 'commentable_id',
106+
'label' => __('Commentable ID'),
107+
'list' => false,
108+
],
109+
[
110+
'attribute' => 'parent_id',
111+
'label' => __('Parent ID'),
112+
'list' => false,
113+
'form_options' => function ($model) {
114+
return [
115+
'field_type' => 'text',
116+
];
117+
},
118+
],
119+
[
120+
'attribute' => 'status',
121+
'label' => __('Status'),
122+
'type' => 'select',
123+
'value' => function ($model) {
124+
return __(array_flip(config('comment.status'))[$model->status]);
125+
},
126+
'form_options' => function ($model) {
127+
$status = [];
128+
foreach (config('comment.status') as $key => $value) {
129+
$status[$value] = __($key);
130+
};
131+
132+
return [
133+
'choices' => $status,
134+
'default_value' => $model ? $model->status : null,
135+
];
136+
},
137+
],
138+
[
139+
'attribute' => 'created_at',
140+
'sortable' => true,
141+
],
142+
[
143+
'attribute' => 'updated_at',
144+
'sortable' => true,
145+
],
146+
];
147+
}
148+
}

app/Grid/Admin/GridHelper.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Grid\Admin;
4+
5+
use BalajiDharma\LaravelCategory\Models\CategoryType;
6+
7+
class GridHelper
8+
{
9+
public static function getTagsField($attribute, $tagName)
10+
{
11+
return [
12+
'attribute' => $attribute,
13+
'label' => __('Tags'),
14+
'list' => false,
15+
'fillable' => true,
16+
'value' => function ($model) use ($tagName) {
17+
return collect($model->getCategoriesByType($tagName)->get())->pluck('name')->implode(', ');
18+
},
19+
'form_options' => function ($model) use ($attribute, $tagName) {
20+
if (old($attribute)) {
21+
if (json_decode(old($attribute))) {
22+
$value = collect(json_decode(old($attribute)))->pluck('value')->implode(',');
23+
} else {
24+
$value = old($attribute);
25+
}
26+
} else {
27+
$value = $model ? collect($model->getCategoriesByType($tagName)->get())->pluck('name')->implode(', ') : '';
28+
}
29+
30+
return [
31+
'field_type' => 'text',
32+
'value' => $value,
33+
'attr' => [
34+
'data-tagify' => 1,
35+
'placeholder' => 'Enter tag',
36+
'data-tagify-maxTags' => 5,
37+
'data-tagify-url' => route('admin.category.type.item.index', CategoryType::where('machine_name', $tagName)->first()->id),
38+
],
39+
];
40+
},
41+
];
42+
}
43+
}

app/Grid/Admin/MediaGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function columns()
7878
return '<div class="avatar"><div class="w-32 rounded">'.$file.'</div><div>';
7979
},
8080
],
81-
include 'includes/tags.php',
81+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
8282
[
8383
'attribute' => 'created_at',
8484
'sortable' => true,

app/Grid/Admin/MenuGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function columns()
7272
];
7373
},
7474
],
75-
include 'includes/tags.php',
75+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
7676
[
7777
'attribute' => 'created_at',
7878
'sortable' => true,

app/Grid/Admin/MenuItemGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function columns()
117117
];
118118
},
119119
],
120-
include 'includes/tags.php',
120+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
121121
[
122122
'attribute' => 'created_at',
123123
'sortable' => true,

app/Grid/Admin/PermissionGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function columns()
5151
'attr' => ['class' => 'link link-primary'],
5252
],
5353
],
54-
include 'includes/tags.php',
54+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
5555
[
5656
'attribute' => 'created_at',
5757
'sortable' => true,

app/Grid/Admin/RoleGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function columns()
8484
];
8585
},
8686
],
87-
include 'includes/tags.php',
87+
GridHelper::getTagsField('admin_tags', config('admin.tag_name')),
8888
[
8989
'attribute' => 'created_at',
9090
'sortable' => true,

0 commit comments

Comments
 (0)