1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Library\Form; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\CrudManager; |
6
|
|
|
use Illuminate\View\Component; |
7
|
|
|
|
8
|
|
|
class FormComponent extends Component |
9
|
|
|
{ |
10
|
|
|
public $crud; |
11
|
|
|
public $operation; |
12
|
|
|
public $formAction; |
13
|
|
|
public $formMethod; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Create a new component instance. |
17
|
|
|
* |
18
|
|
|
* @param string $controller The CRUD controller class name |
19
|
|
|
* @param string $operation The operation to use (create, update, etc.) |
20
|
|
|
* @param string|null $action Custom form action URL |
21
|
|
|
* @param string $method Form method (post, put, etc.) |
22
|
|
|
*/ |
23
|
|
|
public function __construct( |
24
|
|
|
public string $controller, |
25
|
|
|
string $operation = 'create', |
26
|
|
|
?string $action = null, |
27
|
|
|
string $method = 'post' |
28
|
|
|
) { |
29
|
|
|
// Get CRUD panel instance from the controller |
30
|
|
|
$this->crud = CrudManager::crudFromController($controller, $operation); |
|
|
|
|
31
|
|
|
$this->operation = $operation; |
32
|
|
|
$this->formAction = $action ?? url($this->crud->route); |
33
|
|
|
$this->formMethod = $method; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the view / contents that represent the component. |
38
|
|
|
* |
39
|
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string |
40
|
|
|
*/ |
41
|
|
|
public function render() |
42
|
|
|
{ |
43
|
|
|
return view('crud::form.form_component', [ |
44
|
|
|
'crud' => $this->crud, |
45
|
|
|
'operation' => $this->operation, |
46
|
|
|
'formAction' => $this->formAction, |
47
|
|
|
'formMethod' => $this->formMethod, |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
} |