composer require tocaan/sewidan-field
php artisan vendor:publish --provider="SewidanField\SewidanFieldServiceProvider"
You can make field with any type
/**
* @param $name is a field name
* @param $label
* @param null $value
* @param array $field_attributes
* @return string
*/
field()->text('name','label','value',[]);
<div class="form-group " id="{{$name}}_wrap">
<label for="{{$name}}" class="col-md-2" style=""> {{$label}} </label>
<div class="col-md-9" style="">
<input placeholder="{{$label}}" value="{{$value}}" class="form-control" data-name="{{$name}}" id="{{$name}}" name="{{$name}}" type="text">
<span class="help-block" style=""></span>
</div>
</div>
Fields is created using laravel collective
$name // is a field name (string | required)
$label // is a label name (string | required)
$value // is a value of input (string | the default value is null)
you can use it with laravel collective form model
Form::model($model,[attributes])
$field_attributes // is input attributes like class , style
//it take some default values like class : form-control and you can override
// there values like ['class' => 'your-class' , 'style' => 'color:red']
// (array | not required)
// default :
[
"placeholder" => $label,
"class" => "form-control",
"data-name" => $name,
"id" => $name
]
where you Publishing the provider you will find config/field.php
file
you can control the content of HTML
response by creating and switching themes
{{-- container --}} <div class="form-group " id="{{$name}}_wrap">
{{-- label --}} <label for="{{$name}}" class="col-md-2" style=""> {{$label}} </label>
{{-- field_div --}} <div class="col-md-9" style="">
<input placeholder="{{$label}}" value="{{$value}}" class="form-control" data-name="{{$name}}" id="{{$name}}" name="{{$name}}" type="text">
{{-- field_error --}} <span class="help-block" style=""></span>
</div>
</div>
'default_theme' => env('FIELD_DEFAULT_THEME','default'),
'themes' => [
'default' => [
'container' => [
'active' => true,
'class' => 'form-group'
],
'label' => [
'active' => true,
'options' => [
'class' => 'col-md-2',
'style' => ''
],
],
'field_div' => [
'active' => true,
'options' => [
'class' => 'col-md-9',
'style' => ''
],
],
'field_error' => [
'active' => true,
'options' => [
'class' => 'help-block',
'style' => ''
],
],
],
],
you can change the default theme by set key FIELD_DEFAULT_THEME
with your default theme name in
.env
file or change it in config/field.php
'default_theme' => env('FIELD_DEFAULT_THEME','your default theme name')
you can easily but your theme name to field function
field('theme_name')->text('name','label','value',[]);
if you used field without entered theme name automatically function use the default theme
field()->text('name','label','value',[]); // take default theme in config file