|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\NewsCRUD\app\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
|
6
|
|
|
use Backpack\NewsCRUD\app\Http\Requests\ArticleRequest; |
|
7
|
|
|
|
|
8
|
|
|
class ArticleCrudController extends CrudController |
|
9
|
|
|
{ |
|
10
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
|
11
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; |
|
12
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
|
13
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation; |
|
14
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation; |
|
15
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; |
|
16
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation; |
|
17
|
|
|
|
|
18
|
|
|
public function setup() |
|
19
|
|
|
{ |
|
20
|
|
|
/* |
|
21
|
|
|
|-------------------------------------------------------------------------- |
|
22
|
|
|
| BASIC CRUD INFORMATION |
|
23
|
|
|
|-------------------------------------------------------------------------- |
|
24
|
|
|
*/ |
|
25
|
|
|
$this->crud->setModel("Backpack\NewsCRUD\app\Models\Article"); |
|
26
|
|
|
$this->crud->setRoute(config('backpack.base.route_prefix', 'admin').'/article'); |
|
27
|
|
|
$this->crud->setEntityNameStrings('article', 'articles'); |
|
28
|
|
|
|
|
29
|
|
|
/* |
|
30
|
|
|
|-------------------------------------------------------------------------- |
|
31
|
|
|
| LIST OPERATION |
|
32
|
|
|
|-------------------------------------------------------------------------- |
|
33
|
|
|
*/ |
|
34
|
|
|
$this->crud->operation('list', function () { |
|
35
|
|
|
$this->crud->addColumn('title'); |
|
36
|
|
|
$this->crud->addColumn([ |
|
37
|
|
|
'name' => 'date', |
|
38
|
|
|
'label' => 'Date', |
|
39
|
|
|
'type' => 'date', |
|
40
|
|
|
]); |
|
41
|
|
|
$this->crud->addColumn('status'); |
|
42
|
|
|
$this->crud->addColumn([ |
|
43
|
|
|
'name' => 'featured', |
|
44
|
|
|
'label' => 'Featured', |
|
45
|
|
|
'type' => 'check', |
|
46
|
|
|
]); |
|
47
|
|
|
$this->crud->addColumn([ |
|
48
|
|
|
'label' => 'Category', |
|
49
|
|
|
'type' => 'select', |
|
50
|
|
|
'name' => 'category_id', |
|
51
|
|
|
'entity' => 'category', |
|
52
|
|
|
'attribute' => 'name', |
|
53
|
|
|
]); |
|
54
|
|
|
}); |
|
55
|
|
|
|
|
56
|
|
|
/* |
|
57
|
|
|
|-------------------------------------------------------------------------- |
|
58
|
|
|
| CREATE & UPDATE OPERATIONS |
|
59
|
|
|
|-------------------------------------------------------------------------- |
|
60
|
|
|
*/ |
|
61
|
|
|
$this->crud->operation(['create', 'update'], function () { |
|
62
|
|
|
$this->crud->setValidation(ArticleRequest::class); |
|
63
|
|
|
|
|
64
|
|
|
$this->crud->addField([ |
|
65
|
|
|
'name' => 'title', |
|
66
|
|
|
'label' => 'Title', |
|
67
|
|
|
'type' => 'text', |
|
68
|
|
|
'placeholder' => 'Your title here', |
|
69
|
|
|
]); |
|
70
|
|
|
$this->crud->addField([ |
|
71
|
|
|
'name' => 'slug', |
|
72
|
|
|
'label' => 'Slug (URL)', |
|
73
|
|
|
'type' => 'text', |
|
74
|
|
|
'hint' => 'Will be automatically generated from your title, if left empty.', |
|
75
|
|
|
// 'disabled' => 'disabled' |
|
76
|
|
|
]); |
|
77
|
|
|
$this->crud->addField([ |
|
78
|
|
|
'name' => 'date', |
|
79
|
|
|
'label' => 'Date', |
|
80
|
|
|
'type' => 'date', |
|
81
|
|
|
'default' => date('Y-m-d'), |
|
82
|
|
|
]); |
|
83
|
|
|
$this->crud->addField([ |
|
84
|
|
|
'name' => 'content', |
|
85
|
|
|
'label' => 'Content', |
|
86
|
|
|
'type' => 'ckeditor', |
|
87
|
|
|
'placeholder' => 'Your textarea text here', |
|
88
|
|
|
]); |
|
89
|
|
|
$this->crud->addField([ |
|
90
|
|
|
'name' => 'image', |
|
91
|
|
|
'label' => 'Image', |
|
92
|
|
|
'type' => 'browse', |
|
93
|
|
|
]); |
|
94
|
|
|
$this->crud->addField([ |
|
95
|
|
|
'label' => 'Category', |
|
96
|
|
|
'type' => 'select2', |
|
97
|
|
|
'name' => 'category_id', |
|
98
|
|
|
'entity' => 'category', |
|
99
|
|
|
'attribute' => 'name', |
|
100
|
|
|
]); |
|
101
|
|
|
$this->crud->addField([ |
|
102
|
|
|
'label' => 'Tags', |
|
103
|
|
|
'type' => 'select2_multiple', |
|
104
|
|
|
'name' => 'tags', // the method that defines the relationship in your Model |
|
105
|
|
|
'entity' => 'tags', // the method that defines the relationship in your Model |
|
106
|
|
|
'attribute' => 'name', // foreign key attribute that is shown to user |
|
107
|
|
|
'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
|
108
|
|
|
]); |
|
109
|
|
|
$this->crud->addField([ |
|
110
|
|
|
'name' => 'status', |
|
111
|
|
|
'label' => 'Status', |
|
112
|
|
|
'type' => 'enum', |
|
113
|
|
|
]); |
|
114
|
|
|
$this->crud->addField([ |
|
115
|
|
|
'name' => 'featured', |
|
116
|
|
|
'label' => 'Featured item', |
|
117
|
|
|
'type' => 'checkbox', |
|
118
|
|
|
]); |
|
119
|
|
|
}); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|