2017 © Pedro Peláez
 

library laravel-form-helpers

Handle form model binding, old input binding and validation error messages in a clean and easy way.

image

sahibalejandro/laravel-form-helpers

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  • Monday, September 5, 2016
  • by sahibalejandro
  • Repository
  • 2 Watchers
  • 6 Stars
  • 464 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 13 Versions
  • 6 % Grown

The README.md

Laravel Form Helpers

Build Status Latest Stable Version Total Downloads License, (*1)

A set of blade directives that automatically fill forms using the old input or an Eloquent model, it also helps you to display validation error messages in a clean and easy way., (*2)

Example

See how easy is to do cool stuff with these directives, for example if you are using Bootstrap for your markup, you can do something like this:, (*3)



@form($model)
@error('name')

And in the case of the user is redirected back with errors, the result will be:, (*4)



Error message

¡It's awesame!, (*5)

Installation

Install with composer, just run the command:, (*6)

composer require sahibalejandro/laravel-form-helpers

Then add the service provider to your config/app.php file:, (*7)

'providers' => [
    Sahib\Form\FormServiceProvider::class,
];

That's all., (*8)

Configuration

Optionally you can publish the configuration file with this command:, (*9)

php artisan vendor:publish --provider=Sahib\Form\FormServiceProvider

After that you can edit the config/form-helpers.php file., (*10)

Usage

@form

@form([ Model $model = null ]), (*11)

Use the optional @form directive to bind a model to your form.
Ignore this directive if you just want the old input binding and no the model binding., (*12)

<form action="/users/123" method="POST">
    @form($user)
</form>

@input

@input(string $attribute [, string $default = null ]), (*13)

Use the @input directive to assign the value to an input field:, (*14)

<input type="text" @input('name')>
<input type="text" @input('something', 'default')>

This will result in the following markup:, (*15)

<input type="text" name="name" value="">
<input type="text" name="something" value="default"> 

@text

@text(string $attribute [, string $default = null ]), (*16)

Use the @text directive to assign the value to a textarea field:, (*17)

<textarea name="description">@text('description')</textareas>
<textarea name="bio">@text('bio', 'Default')</textareas>

This will result in the following markup:, (*18)

<textarea name="description"></textarea>
<textarea name="bio">Default</textarea>

@checkbox

@checkbox(string $attribute [, mixed $value = 1 [, boolean $checked = false ]]), (*19)

Use the @checkbox to set the value and the state of a checkbox:, (*20)

<input type="checkbox" @checkbox('remember_me')>


<input type="checkbox" @checkbox('newsletter', 'yes')>


<input type="checkbox" @checkbox('send_sms', 1, true)>

This will result in the following markup:, (*21)

<input type="checkbox" name="remember_me" value="1">


<input type="checkbox" name="newsletter" value="yes">


<input type="checkbox" name="send_sms" value="1" checked>

@radio

@radio(string $attribute [, mixed $value = 1 [, boolean $checked = false ]]), (*22)

The @radio directive is used in the same way as @checkbox directive, in fact is just an alias:, (*23)

<input type="radio" @radio('color', 'red')>
<input type="radio" @radio('color', 'green', true)>
<input type="radio" @radio('color', 'blue')>

This will result in the following markup:, (*24)

<input type="radio" name="color" value="red">
<input type="radio" name="color" value="green" checked>
<input type="radio" name="color" value="blue">

@options

@options(array $options, string $attribute [, mixed $default = null [, string $placeholder = null ]]), (*25)

Use the @options directive to display a list of options for a select field., (*26)

Note: It also works with select multiple fields when the model's attribute, old input or $default value is an array., (*27)

Let's say we pass an array named $cardTypes to the view and use it with the @options directive:, (*28)

$cardTypes = [
    'VISA' => 'Visa',
    'MC'   => 'Master Card',
    'AME'  => 'American Express',
];
<select name="card_type">
    @options($cardTypes, 'card_type')
</select>

This will result in the following markup:, (*29)

<select name="card_type">
    <option value="VISA">Visa</option>
    <option value="MC">Master Card</option>
    <option value="AME">American Express</option>
</select>

Of course you can set a default selected option:, (*30)

<select name="card_type">
    @options($cardTypes, 'card_type', 'MC')
</select>

And the result will be:, (*31)

<select name="card_type">
    <option value="VISA">Visa</option>
    <option value="MC" selected>Master Card</option>
    <option value="AME">American Express</option>
</select>

Also you can define a placeholder option:, (*32)

<select name="card_type">
    @options($cardTypes, 'card_type', null, 'Select a card type')
</select>

The result will be:, (*33)

<select name="card_type">
    <option value="" selected disabled>Select a card type</option>
    <option value="VISA">Visa</option>
    <option value="MC">Master Card</option>
    <option value="AME">American Express</option>
</select>

@error

@error(string $attribute [, string $template = null ]), (*34)

Use the @error directive to display a validation error message, this directive will check for you if the error exists or not., (*35)

<input type="text" @input('name')>
@error('name')

Then when the user is redirected back with errors, the result will be:, (*36)

<input type="text" name="name" value="Name That Fail Validation">
<div class="help-block">The name field fails validation.</div>

Note that the @error directive is Bootstrap friendly by default, but you can define a custom template inline or in the config file:, (*37)

@error('name', '<span class="error">:message</span>')

And the result will be:, (*38)

<span class="error">Error message</span>

See how easy is to do cool stuff with @error directive, for example if you are using Bootstrap for your markup, you can do something like this:, (*39)

<div class="form-group @error('name', 'has-error')">
    <input type="text" @input('name')>
    @error('name')
</div>

And in the case the user is redirected back with errors, the result will be:, (*40)

<div class="form-group has-error">
    <input type="text" name="name" value="Bad Name">
    <div class="help-block">Error message</div>
</div>

The Versions

05/09 2016

dev-master

9999999-dev

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

05/09 2016

1.3.1

1.3.1.0

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

05/09 2016

1.3.0

1.3.0.0

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

22/08 2016

1.2.1

1.2.1.0

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

02/08 2016

1.2.0

1.2.0.0

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

01/08 2016

1.1.0

1.1.0.0

Handle form model binding, old input binding and validation error messages in a clean and easy way.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel helpers form validation eloquent html input session

31/07 2016

1.0.6

1.0.6.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

31/07 2016

1.0.5

1.0.5.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

30/07 2016

1.0.4

1.0.4.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

30/07 2016

1.0.3

1.0.3.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

30/07 2016

1.0.2

1.0.2.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

30/07 2016

1.0.1

1.0.1.0

Blade directives to set form values, form model binding couldn't be easier.

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

The Development Requires

by Sahib J. Leo

laravel form eloquent html

29/07 2016

1.0.0

1.0.0.0

Form helpers for laravel

  Sources   Download

MIT

The Requires

 

by Sahib J. Leo

laravel form eloquent html