Skip to content
Pascal Boucher edited this page Oct 8, 2019 · 21 revisions

Installation

Requires php >=7.3.0 and laravel 6.0+

composer require coopbelvedere/laravel-form-maker

php artisan vendor:publish --provider="Belvedere\FormMaker\FormMakerServiceProvider"

This is all there is to do.

Usage

Create your first form.

$form = new \Belvedere\FormMaker\Models\Form\Form();

$form->fill(['name' => 'test form', 'description' => 'Optional description'])
    ->method('post')
    ->action('/post_route')
    ->withHtmlAttributes(['accept-charset' => ['utf8'], 'role' => 'form', 'id' => 'test'])
    ->save();

Add a simple text input with a label element to the form.

$form->add('text')
    ->withHtmlAttributes(['required' => 'required', 'maxlength' => 10])
    ->withRules(['required' => 'required', 'max' => 10])
    ->saveAndFirst()
    ->addLabel('Label');

Return the form in a json format to the client.

return $form->toApi();

A complete overview of the api can be found in the usage section.

Contents

Updating the core

laravel-form-maker makes heavy usage of laravel service container. You can swap most of the package models with your own implementation of the service granted you respect the corresponding contract.

What this means is, you can easily add your custom validation rules to the rule service provider, add a new html attribute on a certain input type or add a new method in the ranking model.

To do so, you just extends the existing class, apply your modifications, and change the path to your new implementation in the config file.

For more details, visit the core update page.

Side note, to reduce performance hit, we make use of laravel deferred providers so the providers are not loaded from the filesystem on every request.

Clone this wiki locally