|
| 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 | +} |
0 commit comments