Package Data | |
---|---|
Maintainer Username: | RobinMalfait |
Maintainer Contact: | malfait.robin@gmail.com (Robin Malfait) |
Package Create Date: | 2013-08-04 |
Package Last Update: | 2016-03-07 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-12-19 03:09:48 |
Package Statistics | |
---|---|
Total Downloads: | 1,609 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 78 |
Total Watchers: | 10 |
Total Forks: | 26 |
Total Open Issues: | 8 |
This is a auto form generator for Laravel 4. This package allows you to auto generate a form from a model.
To add this form generator to your Laravel application follow this steps:
Add the following to your composer.json
file:
"robin-malfait/formgenerator": "dev-master"
Then run composer update
or composer install
if you have not already installed packages.
Add below to the providers
array in app/config/app.php
configuration file (add at the end):
'RobinMalfait\Formgenerator\FormgeneratorServiceProvider'
Add 'Formgenerator' => 'RobinMalfait\Formgenerator\Facades\Formgenerator',
to the aliases
array also in app/config/app.php
'extras' => array(
'*' => array('class' => 'form-control')
)
'customers_id' => array(
'type' => 'hidden',
'value' => 2
)
The ability to add custom labels in the extras
array:
'label' => 'Supercalifragilisticexpialidocious'
Let's make a form now, you can either pass an object like $user
OR you can pass table_name
as a string instead of the $model variable like so:
{{ Form::open() }}
{{ Formgenerator::generate('table_name_here') }}
{{ Form::close() }}
With a $model object
{{ Form::model($user) }}
{{ Formgenerator::generate($user) }}
{{ Form::close() }}
As a second param you can pass an options array for example:
{{ Form::model($user) }}
{{ Formgenerator::generate($user, array(
// If you want a specific type, put it in here, default is type from the database
'types' => array(
// Field Name => Type
'all_day' => 'checkbox',
// Support for hidden fields (auto-hides associated label) and setting values!
'customers_id' => array(
'type' => 'hidden',
'value' => 2
),
// If you want a select field with options
'first_name' => array(
'type' => 'select',
'options' => array(
'Taftse' => 'Taftse',
'Robin' => 'Robin',
'Jeffrey' => 'Jeffrey'
),
),
),
// Add a class to a field
'extras' => array(
// Field Name => array('key' => 'value'),
'first_name' => array(
'class' => 'span5',
'content_before' => '<fieldset><legend>My Form</legend>'
),
'last_name' => array(
'class' => 'span5',
'content_before' => '<br>'
),
'activated' => array(
'class' => '',
'content_after' => '</fieldset>'
// Set a custom label if you want
'label' => 'Supercalifragilisticexpialidocious'
),
// Wildcards, those will be added to every field except for the fields that are listed above.
// If you specify the *form-control* class, all fields will have form-control applied their class list.
// This is great for Bootstrap 3 users, but keep in mind, the above functionality will break due to
// all fields being given a class.
'*' => array(
'class' => 'span5 form-control'
)
),
// Submit? Yes or no? Set the text and set a class if you want
'submit' => array(
'show' => true,
'text' => 'Save',
'class' => 'btn btn-success btn-large'
),
// Fields to not display!
'exclude' => array(
'event_type', 'id', 'created_at', 'updated_at', 'for_user_id'
),
// Show labels
'showLabels' => true,
)) }}
{{ Form::close() }}