|
| 1 | +# Laravel Field Types |
| 2 | + |
| 3 | +The package adds a simple API to Laravel projects to create templated form fields that automatically populates inline error messages, help text and accessibility tags. It is not designed to be a full form manager, instead it removes the repetition when creating form based UIs. |
| 4 | + |
| 5 | +[](https://semaphoreci.com/jamesyps/laravel-field-types) |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* PHP 5.5+ |
| 10 | +* Laravel 5.1+ |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Add the following to your `composer.json` file and run `composer update`. |
| 15 | + |
| 16 | +```json |
| 17 | +"require": { |
| 18 | + "rootstudio/laravel-field-types": "^1.0" |
| 19 | +}, |
| 20 | +"repositories": [ |
| 21 | + { |
| 22 | + "type": "git", |
| 23 | + "url": "git@github.com:RootStudio/Laravel-Field-Types.git" |
| 24 | + } |
| 25 | +] |
| 26 | +``` |
| 27 | + |
| 28 | +Next add the service provider to the `config/apps.php`: |
| 29 | + |
| 30 | +```php |
| 31 | +RootStudio\RootForms\RootFormServiceProvider::class, |
| 32 | +``` |
| 33 | + |
| 34 | +Finally the facade to the aliases config: |
| 35 | + |
| 36 | +```php |
| 37 | +'RootForms' => RootStudio\RootForms\Facades\RootForm::class, |
| 38 | +``` |
| 39 | + |
| 40 | +## Using the package |
| 41 | + |
| 42 | +The package gives the ability to quickly add the following field types: |
| 43 | + |
| 44 | +* text |
| 45 | +* email |
| 46 | +* tel |
| 47 | +* password |
| 48 | +* checkbox set |
| 49 | +* radio set |
| 50 | +* select |
| 51 | +* file |
| 52 | +* toggle |
| 53 | +* confirm |
| 54 | + |
| 55 | +For example, to create a simple text fields: |
| 56 | + |
| 57 | +```blade |
| 58 | +{!! RootForms::text('name', 'Your name', old('name')) !!} |
| 59 | +{!! RootForms::email('login', 'Your email', old('login')) !!} |
| 60 | +{!! RootForms::password('password', 'Your password') !!} |
| 61 | +``` |
| 62 | + |
| 63 | +*Note: password field types do not accept a value parameter* |
| 64 | + |
| 65 | +You can optionally include additional classes or attributes: |
| 66 | + |
| 67 | +```blade |
| 68 | +{!! RootForms::text('name', 'Your name', old('name'), 'js-autosuggest', ['required' => true]) !!} |
| 69 | +``` |
| 70 | + |
| 71 | +Multiple choice fields use a similar syntax: |
| 72 | + |
| 73 | +```blade |
| 74 | +{!! RootForms::select('country', 'Shipping destination', ['uk' => 'United Kingdom', 'usa' => 'United States'], old('country')) !!} |
| 75 | +{!! RootForms::radio_set('method', 'Shipping method', ['standard' => 'Royal Mail', 'priority' => 'FedEx'], old('method')) !!} |
| 76 | +{!! RootForms::checkbox_set('extras', 'Include the following', ['gift' => 'Gift Wrap', 'sms' => 'SMS Notifications'], old('extras')) !!} |
| 77 | +``` |
| 78 | + |
| 79 | +Boolean fields do not take additional options, only true or false: |
| 80 | + |
| 81 | +```blade |
| 82 | +{!! RootForms::toggle('send_emails', 'Would you like to be emailed?', old('send_emails')) !!} |
| 83 | +{!! RootForms::confirm('terms_agreement', 'Have you read the terms & conditions?', old('terms_agreement')) !!} |
| 84 | +``` |
| 85 | + |
| 86 | +## Customising |
| 87 | + |
| 88 | +The package templates are built for Bootstrap v4. If you wish to customise these and use your own styling and classes the views can be published using artisan: |
| 89 | + |
| 90 | +``` |
| 91 | +php artisan vendor:publish --provider="RootStudio\RootForms\RootFormsServiceProvider" --tag="views" |
| 92 | +``` |
| 93 | + |
| 94 | +To change the location of the view files export the config file: |
| 95 | + |
| 96 | +``` |
| 97 | +php artisan vendor:publish --provider="RootStudio\RootForms\RootFormsServiceProvider" --tag="config" |
| 98 | +``` |
0 commit comments