1. Go to this page and download the library: Download iyoworks/former library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Client extends Eloquent
{
public static $key = 'code';
public function __toString()
{
return $this->name;
}
}
Former::select('clients')->fromQuery(Client::all());
Former::populate(Client::find(2))
// Will populate with $client->name
Former::text('name')
// Will populate with $client->store->name
Former::text('store.name')
// You can go as deep as you need to
Former::text('customer.name.adress')
// Will populate with the date from all of the client's reservations
Former::select('reservations.date')
// Which is the same as this ^
Former::select('reservations')->fromQuery($client->reservations, 'date')
// If you're using a text and not a select, instead of listing the
// relationship's models as options, it wil concatenate them
Former::text('customers.name') // Will display "name, name, name"
// You can rename a field afterwards for easier Input handling
Former::text('comment.title')->name('title')
Former::text('clients')->useDatalist($clients)
// Or use a Query object, same syntax than fromQuery()
Former::text('projects')->useDatalist(Project::all(), 'name')
// Use a shortcut (image, video or audio)
Former::files('avatar')->accept('image')
// Use an extension which will be converted to MIME by Laravel
Former::files('avatar')->accept('gif', 'jpg')
// Or directly use a MIME
Former::files('avatar')->accept('image/jpeg', 'image/png')
// Create a one-off checkbox
Former::checkbox('checkme')
// Create a one-off checkbox with a text, and check it
Former::checkbox('checkme')
->text('YO CHECK THIS OUT')
->check()
// Create four related checkboxes
Former::checkboxes('checkme')
->checkboxes('first', 'second', 'third', 'fourth')
// Create related checkboxes, and inline them
Former::checkboxes('checkme')
->checkboxes($checkboxes)->inline()
// Everything that works on a checkbox also works on a radio element
Former::radios('radio')
->radios(array('label' => 'name', 'label' => 'name'))
->stacked()
// Stacked and inline can also be called as magic methods
Former::inline_checkboxes('foo')->checkboxes('foo', 'bar')
Former::stacked_radios('foo')->radios('foo', 'bar')
// Set which checkables are checked or not in one move
Former::checkboxes('level')
->checkboxes(0, 1, 2)
->check(array('level_0' => true, 'level_1' => false, 'level_2' => true))
// Fine tune checkable elements
Former::radios('radio')
->radios(array(
'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),
'label' => array('name' => 'foo', 'value' => 'bar', 'data-foo' => 'bar'),
))
// This
Former::label(__('validation.attributes.name'))
Former::text('name', __('validation.attributes.name'))
Former::text('name')->inlineHelp(__('help.name'))
Former::checkbox('rules')->text(__('my.translation'))
<legend>{{ __('validation.attributes.mylegend') }}</legend>
// Is the same as this
Former::label('name')
Former::text('name')
Former::text('name')->inlineHelp('help.name')
Former::checkbox('rules')->text('my.translation')
Former::legend('mylegend')
// Laravel
<div class="control-group">
{{ Form::label('input01', __('validation.attributes.input01'), array('class' => 'control-label') )}}
<div class="controls">
<div class="input-prepend input-append">
<span class="add-on">@</span>
{{ Form::text('input01', 'myname', (Input::get('input01', Input::old('input01')), array('class' => 'input-xlarge')) }}
<span class="add-on"><i class="icon-white icon-enveloppe"></i></span>
</div>
<p class="help-block">This is an help text</p>
</div>
</div>
// Bootstrapper
echo Form::prepend_append(
Form::control_group(
Form::label('input01', __('validation.attributes.input01')),
Form::xlarge_text('input01'),
(Input::get('input01', Input::old('input01', 'myname'))),
$validation->errors->get('input01'),
Form::block_help('This is an help text')
),
'@', Icon::white_enveloppe()
);
// Former
Former::xlarge_text('input01', 'Text input')
->blockHelp('This is an help text')
->prepend('@')->appendIcon('white-enveloppe')
->value('myname')
// Laravel
// Man don't even get me started
// Boostrapper
echo Form::control_group(
Form::label('checkboxes', 'Check those boxes'),
Form::inline_labelled_checkbox('check1', 'Check me', 1, Input::get('check1', Input::old('check1'))).
Form::inline_labelled_checkbox('check2', 'Check me too', 1, Input::get('check2', Input::old('check2'))),
$validation->errors->get('check1'),
Form::inline_help('I SAID CHECK THOSE DOUBLES')
);
// Former
Former::checkboxes('check')
->checkboxes('Check me', 'Check me too')
->help('I SAID CHECK THOSE DOUBLES')
bash
php artisan bundle:install former
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.