-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostCrudController.php
125 lines (115 loc) · 3.78 KB
/
PostCrudController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\PostRequest;
use App\Models\Post;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class PostCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class PostCrudController extends CrudController
{
use ListOperation;
use CreateOperation;
use UpdateOperation;
use DeleteOperation;
use ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(Post::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/post');
CRUD::setEntityNameStrings('post', 'posts');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
CRUD::setFromDb(); // set columns from db columns.
/**
* Columns can be defined using the fluent syntax:
* - CRUD::column('price')->type('number');
*/
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(PostRequest::class);
//CRUD::setFromDb(); // set fields from db columns.
$this->crud->addFields(
[
[
'name' => 'title',
'label' => 'Post Title',
'type' => 'text',
],
[
'name' => 'description',
'label' => 'Post Description',
'type' => 'text',
]
]
);
$this->crud->addFields(
[
[
'name' => 'subPost',
// We use repeatable instead of relationship to have more control over the rows etc
'type' => "repeatable",
'init_rows' => 1, // By default
'min_rows' => 1, // You cannot delete the last one
'max_rows' => 1, // You cannot add more rows
'label' => 'subPost',
'subfields' => [
[
'name' => 'title',
'label' => 'Title'
],
[
'name' => 'description',
'label' => 'Description',
'type' => 'text',
],
[
'name' => 'main_image',
'label' => 'Main Image',
'type' => 'image',
'withMedia' => [
],
],
],
]
]
);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
}