1
|
|
|
<?php namespace Distilleries\Expendable\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
use Distilleries\Expendable\Contracts\LayoutManagerContract; |
4
|
|
|
use Distilleries\Expendable\Formatter\Message; |
5
|
|
|
use Distilleries\Expendable\Http\Forms\Component\ComponentForm; |
6
|
|
|
use Distilleries\Expendable\Http\Controllers\Backend\Base\BaseController; |
7
|
|
|
use Distilleries\FormBuilder\Contracts\FormStateContract; |
8
|
|
|
use Illuminate\Contracts\Console\Kernel; |
9
|
|
|
use Illuminate\Http\Request; |
10
|
|
|
use \FormBuilder; |
11
|
|
|
|
12
|
|
|
class ComponentController extends BaseController implements FormStateContract { |
13
|
|
|
|
14
|
|
|
protected $artisan; |
15
|
|
|
|
16
|
8 |
|
public function __construct(Kernel $artisan, ComponentForm $form, LayoutManagerContract $layoutManager) |
17
|
|
|
{ |
18
|
8 |
|
parent::__construct($layoutManager); |
19
|
8 |
|
$this->form = $form; |
|
|
|
|
20
|
8 |
|
$this->artisan = $artisan; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
// ------------------------------------------------------------------------------------------------ |
26
|
|
|
// ------------------------------------------------------------------------------------------------ |
27
|
|
|
// ------------------------------------------------------------------------------------------------ |
28
|
|
|
|
29
|
2 |
|
public function getIndex() |
30
|
|
|
{ |
31
|
2 |
|
return redirect()->to(action('\\'.get_class($this).'@getEdit')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
// ------------------------------------------------------------------------------------------------ |
36
|
|
|
// ------------------------------------------------------------------------------------------------ |
37
|
|
|
// ------------------------------------------------------------------------------------------------ |
38
|
|
|
|
39
|
2 |
|
public function getEdit($id = '') |
40
|
|
|
{ |
41
|
|
|
|
42
|
2 |
|
$form = FormBuilder::create(get_class($this->form)); |
43
|
|
|
|
44
|
|
|
|
45
|
2 |
|
$form_content = view('form-builder::form.components.formgenerator.full', [ |
46
|
2 |
|
'form' => $form |
47
|
|
|
]); |
48
|
2 |
|
$content = view('expendable::admin.form.state.form', [ |
49
|
|
|
|
50
|
2 |
|
]); |
51
|
|
|
|
52
|
2 |
|
$this->layoutManager->add([ |
53
|
2 |
|
'form' => $form_content, |
54
|
2 |
|
'content' => $content, |
55
|
|
|
]); |
56
|
|
|
|
57
|
2 |
|
return $this->layoutManager->render(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// ------------------------------------------------------------------------------------------------ |
61
|
|
|
|
62
|
4 |
|
public function postEdit(Request $request) |
63
|
|
|
{ |
64
|
|
|
|
65
|
4 |
|
$form = FormBuilder::create(get_class($this->form)); |
66
|
|
|
|
67
|
4 |
|
if ($form->hasError()) |
68
|
|
|
{ |
69
|
2 |
|
return $form->validateAndRedirectBack(); |
70
|
|
|
} |
71
|
|
|
|
72
|
2 |
|
$libelle = $request->get('libelle'); |
73
|
2 |
|
$libelle_form = $libelle.'Form'; |
74
|
2 |
|
$libelle_datatable = $libelle.'Datatable'; |
75
|
2 |
|
$libelle_controller = $libelle.'Controller'; |
76
|
2 |
|
$model = $request->get('models'); |
77
|
2 |
|
$states = $request->get('state'); |
78
|
|
|
|
79
|
2 |
|
foreach ($states as $state) |
80
|
|
|
{ |
81
|
2 |
|
if (strpos($state, 'DatatableStateContract') !== false) |
82
|
|
|
{ |
83
|
2 |
|
$this->artisan->call('datatable:make', [ |
84
|
2 |
|
'--fields' => $request->get('colon_datatable'), |
85
|
2 |
|
'name' => 'Http/Datatables/'.$libelle_datatable |
86
|
|
|
]); |
87
|
2 |
|
} else if (strpos($state, 'FormStateContract') !== false) |
88
|
|
|
{ |
89
|
|
|
|
90
|
2 |
|
$this->artisan->call('make:form', [ |
91
|
2 |
|
'--fields' => $request->get('fields_form'), |
92
|
2 |
|
'name' => 'Http/Forms/'.$libelle_form |
93
|
|
|
]); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
2 |
|
$this->artisan->call('expendable:component.make', [ |
98
|
2 |
|
'--states' => join(',', $states), |
99
|
2 |
|
'--model' => $model, |
100
|
2 |
|
'--datatable' => $libelle_datatable, |
101
|
2 |
|
'--form' => $libelle_form, |
102
|
2 |
|
'name' => 'Http/Controllers/Backend/'.$libelle_controller |
103
|
|
|
]); |
104
|
|
|
|
105
|
2 |
|
return redirect()->back()->with(Message::MESSAGE, [trans('expendable::success.generated')]); |
106
|
|
|
} |
107
|
|
|
} |