project-management/app/View/Components/ModelFormControlGroup.php
2022-05-04 01:00:10 +08:00

55 lines
1.2 KiB
PHP

<?php
namespace App\View\Components;
use Illuminate\Support\Str;
use Illuminate\View\Component;
class ModelFormControlGroup extends Component
{
public $model;
public $type;
public $inputType;
public $required;
public $attr;
public $value;
public $id;
public $label;
public $options;
public $multiple;
public function __construct($model, $attr, $label = null, $type = 'input', $inputType = 'text', $required = false, $id = null, $value = null,
$options = [], $multiple = false)
{
$this->model = $model;
$this->type = $type;
$this->inputType = $inputType;
$this->required = $required;
$this->attr = $attr;
$this->value = $value ? $value : ($model->id ? $model->{$attr} : old($attr));
$this->id = $id ? $id : $model::class . '-' . $attr;
$this->label = $label ? $label : Str::ucfirst($attr);
$this->options = $options;
$this->multiple = $multiple;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.model-form-control-group');
}
}