2.1 Form Methods - joserick/laravel-bootstrap-4-forms GitHub Wiki

Form methods

Chainable methods

This package uses chaining feature, allowing easly pass more parameters.

Filling a form

Param Type Default Description
$data object/array array Data fo fill form inputs
// Examples

// With initial data using a Model instance
$user = User::find(1);
{!!Form::open()->fill($user)!!}

// With initial array data
$user = ['name' => 'Jesus', 'age' => 33];
{!!Form::open()->fill($user)!!}

Url

Use in forms openings and anchors

Param Type Default Description
$url string null Url
// Example
{!!Form::open()->url('foo/bar')!!}

Route

Use in forms openings and anchors

Param Type Default Description
$route string null Route name
// Example
{!!Form::open()->route('home')!!}

Locale

Using locale, the package will look for a resources/lang/{CURRENT_LANG}/forms/user.php language file and uses labels and help texts as keys for replace texts

Param Type Default Description
$locale string none Locale name
// Example
{!!Form::open()->locale('forms.user')!!}

AutoFill

Param Type Default Description
$value string 'on' autocomplte value
// Examples

// Switch off autocomplete for the form
{!!Form::open()->autocomplete('off')!!}

Id prefix

Param Type Default Description
$prefix string null Id prefix
// Example
{!!Form::open()->idPrefix('register')!!}

Multipart

Param Type Default Description
$multipart boolean true Multipart flag
// Examples
{!!Form::open()->multipart()!!}

// You can use FALSE to turn off multipart
{!!Form::open()->multipart(false)!!}

Method

Param Type Default Description
$method string null HTTP method
// Examples
{!!Form::open()->method('get')!!}
{!!Form::open()->method('post')!!}
{!!Form::open()->method('put')!!}
{!!Form::open()->method('patch')!!}
{!!Form::open()->method('delete')!!}

Explicit HTTP verbs

// Examples
{!!Form::open()->get()!!}
{!!Form::open()->post()!!}
{!!Form::open()->put()!!}
{!!Form::open()->patch()!!}
{!!Form::open()->delete()!!}

Error Bag

Use if you have more then one form per page. You set an identifier for each form, and the errors will be attached for that specific form

Param Type Default Description
$value string null Error bag name
// Example: attach this form to a error bag called "registerErrorBag"
{!!Form::open()->route('register.post')->errorBag("registerErrorBag")!!}

// ------------------------------------------------------

// Now, in your controller (register.post route), you can redirect the user to a form page again, with erros inside a error bag called "registerErrorBag"
public function register(Request $request)
{
    $validator = Validator::make($request->all(), [
        // ... rules here
    ]);

    if ($validator->fails()) {
        return redirect()
            ->route('register.form')
            ->withInput()
            ->withErrors($validator, 'registerErrorBag');
    }

    // Proced to register here
}