2017 © Pedro Peláez
 

library smart-schema

Form helper for Laravel

image

appoly/smart-schema

Form helper for Laravel

  • Saturday, July 14, 2018
  • by Mezzair
  • Repository
  • 2 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Laravel: Smartfields & form helper

Tired of repeating yourself? This package centralises everything to do with fields., (*1)

Navigation - Introduction - Field Types - Virtual Fields - Validation Rules - Model Attributes - Forms - Code Generation, (*2)

Quick Usage

Add to composer.json:, (*3)

"appoly/smart-schema": "^0.6.3",

Introduction

Instead of having to create a migration, a request, form views and set up fillable fields, we can instead create a smart migration which handles it all., (*4)

Example migration:, (*5)

SmartSchema::create('sites', function ($table) {
    $table->increments("id");

    $table->integer("name");

    $table->text("name")
        ->nullable()
        ->required()
        ->fillable()
        ->max(5)
        ->forms([
            'type' => 'text',
            'label' => 'Site name'
        ]);

    $table->timestamps();
});

Options for fields

Field Types

Standard field types area available., (*6)

$table->text("name")
$table->integer("user_id")
$table->float("latitude")

etc..., (*7)

Virtual Fields

In some cases, we may want fields in a form that don't correspond directy to our database tables., (*8)

We can then use:, (*9)

$table->virtual("slot")->forms(...

Validation Rules

These can be chained to a field creation in your migration., (*10)

Example:, (*11)

$table->text("email")->required()->email();

Available rules:, (*12)

->unique()
->required()
->email()
->max( val )
->min( val )

Custom validation rules can be added with:, (*13)

->addRule( rule )

When storing the object in your controller, the validation helper should be called with the object type:, (*14)

public function store(Request $request) {
    SchemaHelper::validate($request, 'sites');

    // Process the request
    // ...
}

Model attributes

fillable(), (*15)

Casts:, (*16)

->array()
->datetime()

Model must have the SmartField trait to use fillable() or any of the attribute casts., (*17)

class User extends Model
{
    use SmartField;
}

Forms

The form helper will generate (currently Bootstrap 4) forms based on the field data., (*18)

In migration, use ->forms([... to show a field in the auto-generated forms:, (*19)

->forms([
    'type' => 'text',
    'label' => 'Site name'
])

To render a basic form:, (*20)

{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store')) !!}

Multiple choice form fields such as selects and radio buttons will need a set of options., (*21)

In the case of the following field:, (*22)

$table->id("role")
        ->forms([
            'type' => 'select', // or 'type' => 'radio'
            'label' => 'Role'
        ]);

Options can be passed like so:, (*23)

{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store'), [
    'select_options' => [
        'role_id' => ['User', 'Admin']
    ]
]) !!}

Or with keys, (*24)

{!! \Appoly\SmartSchema\SchemaHelper::form('sites', route('sites.store'), [
    'select_options' => [
        'role_id' => [
            10001 => 'User', 
            20001 => 'Admin'
        ]
    ]
]) !!}

Code Generation

This package includes a console command which will set up a boilerplate controller and view code., (*25)

php artisan crud:generate {resource_name_singular}, (*26)

For example:, (*27)

php artisan crud:generate client, (*28)

The Versions

14/07 2018

dev-master

9999999-dev

Form helper for Laravel

  Sources   Download

by Appoly

05/07 2018

0.0.4

0.0.4.0

Form helper for Laravel

  Sources   Download

by Appoly

05/07 2018

0.0.2

0.0.2.0

Form helper for Laravel

  Sources   Download

by Appoly

05/07 2018

0.0.1

0.0.1.0

Form helper for Laravel

  Sources   Download

by Appoly