gustiawan / laravel-form-builder
Laravel Form Builder
Installs: 2 503
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 2
Open Issues: 0
Requires
- php: >=7.1
- illuminate/support: ^7.0|^8.0|^9.0|^10
- illuminate/validation: ^7.0|^8.0|^9.0|^10
README
Installation
composer require gustiawan/laravel-form-builder
run this command to publish package
php artisan vendor:publish --provider="Gustiawan\FormBuilder\FormBuilderServiceProvider"
configuration
change style to bootstrap if you want to use bootstrap styling
/** * Set your default styling * the option is [tailwind, bootstrap] */ "style" => "tailwind",
change this only if you want to use custom form template
/** * Fill this with your view path */ "form_template" => null
Usage
create form using
php artisan make:form {name}
the file is written in App/Form
add your form depends on your need
use Gustiawan\FormBuilder\Form; class ExampleForm extends Form { public function handle() { $this->text("textinput", "Text Input"); $this->password("password", "Old Password"); $this->textArea("text area", "Text Area", "Default Value"); $this->date("example_date", "Example Date"); $this->radio("radio_example", "Radio Example", [1 => "Option one", 2 => "Option two"], ["value" => 1]); // default value $this->checkBox("checkbox_example", "Checkbox Example", [1 => "Option one", 2 => "Option two"], ["value" => [1, 2]]); // default value must be array $this->select("select_field", "Select Field Example", [1 => "Option one", 2 => "Option two"], ["value" => 1]); // default value } }
then inside your controller
public function example() { $form = new ExampleForm([ "action" => route('example_routes'), "method" => "POST", // optional "data" => [ "field_name" => "some value" ] ]); return view('example_view', compact('form')); }
in your view
<x-form-generator-form :form="$form" />
field options
to add default value to the field
$this->text("textinput", "Text Input", ["value" => "some value"]);
to make field is required field
$this->text("textinput", "Text Input", ["required" => true]);
to make field readonly
$this->text("textinput", "Text Input", ["readonly" => true]);
to make field disabled
$this->text("textinput", "Text Input", ["disabled" => true]);
to add custom class to the inputs
$this->text("textinput", "Text Input", ["class" => "datetimepicker"]);