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 $operation = 'create', |
23
|
|
|
public ?string $formAction = null, |
24
|
|
|
public string $formMethod = 'post' |
25
|
|
|
) { |
26
|
|
|
// Get CRUD panel instance from the controller |
27
|
|
|
$this->crud = CrudManager::setupCrudPanel($controller, $operation); |
|
|
|
|
28
|
|
|
$this->operation = $operation; |
29
|
|
|
$this->formAction = $action ?? url($this->crud->route); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the view / contents that represent the component. |
34
|
|
|
* |
35
|
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string |
36
|
|
|
*/ |
37
|
|
|
public function render() |
38
|
|
|
{ |
39
|
|
|
return view('crud::components.form.form', [ |
40
|
|
|
'crud' => $this->crud, |
41
|
|
|
'operation' => $this->operation, |
42
|
|
|
'formAction' => $this->formAction, |
43
|
|
|
'formMethod' => $this->formMethod, |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
} |