I want to create dynamic field on my controller and pass variable to blade. I have controller like this
public function create()
{
$AdditionalField=AdditionalFieldController::generateHTML(1);
return view("addcontact")->with(['AdditionalField'=$AdditionalField]);
}
output of print_r($AdditionalField)
is:
<div class="col-lg-1 col-md-12 col-sm-12 text-right">
<label class="text-gray-dark" for="address_2">address_2</label>
</div>
<div class="col-lg-3 col-md-8 col-sm-12">
<input class="form-control " id="address_2" value="{{isset($editContact['address_2'])?$editContact['address_2']:''}}" name="address_2">
</div>
and on my blade I use this code for show fields.
{!! $AdditionalField !!}
Output is
but I want to show me this on blade
Updated
public static function generateHTML($moduleId)
{
$AdditionalFieldKeys = AdditionalFieldKey::where("module_id", $moduleId)->get();
$html = '';
foreach ($AdditionalFieldKeys as $additionalFieldKey) {
$type = AdditionalFieldController::getInputType($additionalFieldKey->additional_field_key_name);
$fieldName = AdditionalFieldController::getInputName($additionalFieldKey->additional_field_key_name);
$file = AdditionalFieldController::getTemplate($type);
$variable = AdditionalFieldController::getVariables($fieldName,$this->model_name);
$html .= AdditionalFieldController::fillTemplate($variable, $file);
}
return $html;
}
public static function getTemplate($type)
{
$file = base_path('modules/AdditionalField/view/' . $type . '.stub');
return file_get_contents($file);
}