Skip to content

iYahiaa/sewidan-fields

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel package for form fields

Installation

You can install the package via composer

composer require tocaan/sewidan-field

Publish the configuration file

php artisan vendor:publish --provider="SewidanField\SewidanFieldServiceProvider"

Usage

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',[]);
Output
   <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>

Params

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
      ]
     

configuration file

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

themes map keys

   {{-- 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>

Control Themes in config/field.php

    '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')

switching themes while creating field

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 72.2%
  • PHP 22.9%
  • CSS 2.6%
  • Blade 2.3%