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