Skip to content

Instantly share code, notes, and snippets.

@bsadnu
Last active October 14, 2016 07:43
Show Gist options
  • Save bsadnu/b9ae489fb396bebf0ddc27b95d94153c to your computer and use it in GitHub Desktop.
Save bsadnu/b9ae489fb396bebf0ddc27b95d94153c to your computer and use it in GitHub Desktop.
Extends Appzcoder\CrudGenerator generate view command. Particulary changes %%formFieldsHtml%% for compatibility with StartUI Admin Html template.
<?php
namespace App\Console\Commands;
use Appzcoder\CrudGenerator\Commands\CrudViewCommand;
/**
* Extends Appzcoder\CrudGenerator generate view command. Particulary changes %%formFieldsHtml%% for compatibility with StartUI Admin Html template.
*/
class CrudViewCommandCustom extends CrudViewCommand
{
/**
* Form field wrapper.
*
* @param string $item
* @param string $field
*
* @return void
*/
protected function wrapField($item, $field)
{
$formGroup =
<<<EOD
<div class="col-lg-12">
<fieldset class="form-group">
{!! Form::label('%1\$s', %2\$s, ['class' => 'form-label semibold', 'for' => 'title']) !!}
%3\$s
{!! \$errors->first('%1\$s', '<small class="text-muted">:message</small>') !!}
</fieldset>
</div>\n
EOD;
$labelText = "'" . ucwords(strtolower(str_replace('_', ' ', $item['name']))) . "'";
if ($this->option('localize') == 'yes') {
$labelText = 'trans(\'' . $this->crudName . '.' . $item['name'] . '\')';
}
return sprintf($formGroup, $item['name'], $labelText, $field);
}
/**
* Create a specific field using the form helper.
*
* @param array $item
*
* @return string
*/
protected function createFormField($item)
{
$required = ($item['required'] === true) ? ", 'required' => 'required'" : "";
return $this->wrapField(
$item,
"{!! Form::" . $this->typeLookup[$item['type']] . "('" . $item['name'] . "', null, ['class' => 'form-control ' . (\$errors->has('" . $item['name'] . "') ? 'form-control-error' : ''), 'id' => '" . $item['name'] . "'$required]) !!}"
);
}
/**
* Create a password field using the form helper.
*
* @param array $item
*
* @return string
*/
protected function createPasswordField($item)
{
$required = ($item['required'] === true) ? ", 'required' => 'required'" : "";
return $this->wrapField(
$item,
"{!! Form::password('" . $item['name'] . "', ['class' => 'form-control ' . (\$errors->has('" . $item['name'] . "') ? 'form-control-error' : ''), 'id' => '" . $item['name'] . "'$required]) !!}"
);
}
/**
* Create a generic input field using the form helper.
*
* @param array $item
*
* @return string
*/
protected function createInputField($item)
{
$required = ($item['required'] === true) ? ", 'required' => 'required'" : "";
return $this->wrapField(
$item,
"{!! Form::input('" . $this->typeLookup[$item['type']] . "', '" . $item['name'] . "', null, ['class' => 'form-control ' . (\$errors->has('" . $item['name'] . "') ? 'form-control-error' : ''), 'id' => '" . $item['name'] . "'$required]) !!}"
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment