PHPackages                             laraeast/laravel-bootstrap-forms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. laraeast/laravel-bootstrap-forms

ActivePackage[Utility &amp; Helpers](/categories/utility)

laraeast/laravel-bootstrap-forms
================================

Provides an easy way to use bootstrap components within your Laravel projects.

v10.2.1(3mo ago)955.5k↓37.5%81MITBladePHP ^8.2CI passing

Since Mar 4Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/laraeast/laravel-bootstrap-forms)[ Packagist](https://packagist.org/packages/laraeast/laravel-bootstrap-forms)[ RSS](/packages/laraeast-laravel-bootstrap-forms/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (56)Used By (1)

\# Laravel Bootstrap Forms.
===========================

[](#-laravel-bootstrap-forms)

[![Build Status](https://github.com/laraeast/laravel-bootstrap-forms/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/laraeast/laravel-bootstrap-forms/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/cc19b5149f0d6b6f6bd76c6c6707b941c541577bcb6cbbd399de9b7dbc46c3d3/68747470733a2f2f706f7365722e707567782e6f72672f6c617261656173742f6c61726176656c2d626f6f7473747261702d666f726d732f642f746f74616c2e737667)](https://packagist.org/packages/laraeast/laravel-bootstrap-forms)[![Latest Stable Version](https://camo.githubusercontent.com/f7f148650fd3010a3c6cdd014a01c38039554d8b5244a93092ab5aba905bea92/68747470733a2f2f706f7365722e707567782e6f72672f6c617261656173742f6c61726176656c2d626f6f7473747261702d666f726d732f762f737461626c652e737667)](https://packagist.org/packages/laraeast/laravel-bootstrap-forms)[![License](https://camo.githubusercontent.com/9e0baf0d4399de12d2df95ce5157d5cc22e7ac5c873e902965989b08d75285ab/68747470733a2f2f706f7365722e707567782e6f72672f6c617261656173742f6c61726176656c2d626f6f7473747261702d666f726d732f6c6963656e73652e737667)](https://packagist.org/packages/laraeast/laravel-bootstrap-forms)

- [Installation](#installation)
- [Opening A Form](#opening-a-form)
- [Text, Text Area, Date, Number, Files, Base64Image, attachment, Color &amp; Password Fields](#fields)
- [Price Field](#price)
- [Phone Field](#phone)
- [Checkboxes and Radio Buttons](#checkboxes)
- [Drop-Down Lists](#dropdown)
- [Generating A Submit Button](#submit)
- [Supported Methods](#methods)
- [Using Resource With Localed Fields](#resource)
- [Example Register Form](#example)
- [Add Custom Style To The Component](#custom-style)
- [Using Multilingual Form Tabs](#multilingual)
- [Manage Locales](#locales)
- [Using Bootstrap 3 or 4](#bootstrap3)
- [Add Custom Component](#custom-component)

\# Installation
===============

[](#-installation)

> Begin by installing this package through Composer. Edit your project's `composer.json` file to require `laraeast/laravel-bootstrap-forms`.

```
composer require laraeast/laravel-bootstrap-forms
```

\# Opening A Form
=================

[](#-opening-a-form)

```
{{ BsForm::open($url) }}
//
{{ BsForm::close() }}
```

> By default, a `POST` method will be assumed; however, you are free to specify another method:

```
{{ BsForm::open($url, ['method' => 'post']) }}
```

> Note: Since HTML forms only support `POST` and `GET`, `PUT` and `DELETE` methods will be spoofed by automatically adding a `_method` hidden field to your form.

> You may also open forms with method as well:

```
{{ BsForm::get('foo/bar') }}
{{ BsForm::post('foo/bar') }}
{{ BsForm::put('foo/bar') }}
{{ BsForm::patch('foo/bar') }}
{{ BsForm::delete('foo/bar') }}
{{ BsForm::model($model, 'foo/bar') }}
{{ BsForm::putModel($model, 'foo/bar') }}
{{ BsForm::patchModel($model, 'foo/bar') }}
```

> You may also open forms that point to named routes or controller actions:

```
{{ BsForm::open(['route' => 'route.name']) }}
{{ BsForm::open(['action' => 'Controller@method']) }}
```

> You may pass in route parameters as well:

```
{{ BsForm::open(['route' => ['route.name', $user->id]]) }}
{{ BsForm::open(['action' => ['Controller@method', $user->id]]) }}
```

\# Text, Text Area, Date, Number &amp; Password Fields
======================================================

[](#-text-text-area-date-number--password-fields)

> Generating A Text Input

```
{{ BsForm::text('username') }}
```

Specifying A Default Value
--------------------------

[](#specifying-a-default-value)

```
{{ BsForm::text('email', 'example@gmail.com') }}
{{ BsForm::text('email')->value('example@gmail.com') }}
```

> Note: The date, number and textarea methods have the same signature as the text method.

Generating A Password Input
---------------------------

[](#generating-a-password-input)

```
{{ BsForm::password('password', ['class' => 'awesome']) }}
{{ BsForm::password('password')->attr('class', 'awesome') }}
```

Generating Other Inputs
-----------------------

[](#generating-other-inputs)

```
{{ BsForm::email($name)->value($value)->label($label) }}
{{ BsForm::file($name)->label('Upload File') }}
```

Multilingual Forms (text &amp; textarea)
----------------------------------------

[](#multilingual-forms-text--textarea)

```
@multilingualFormTabs
    {{ BsForm::text('title')->value(old('title:'.$locale->code))->label($label) }}
@endMultilingualFormTabs
```

> The name attribute will be `name:{lang}`
>
> The variable `$locale` is preset inside `@multilingualFormTabs` and `@endMultilingualFormTabs` and it contains the iterator of `Locales::get()` see: [Laravel Locales Package](https://github.com/laraeast/laravel-locales)

\# Checkboxes and Radio Buttons
===============================

[](#-checkboxes-and-radio-buttons)

Generating A Checkbox Or Radio Input
------------------------------------

[](#generating-a-checkbox-or-radio-input)

```
{{ BsForm::checkbox('name', 'value')->checked(false) }}
{{ BsForm::checkbox('name')->value('value')->checked(false) }}
{{ BsForm::checkbox('name')->value(1)->withDefault()->checked(false) }} {{-- If unchecked will send "0" with request --}}
{{ BsForm::checkbox('name')->value(1)->withoutDefault()->checked(false) }}
{{ BsForm::checkbox('name')->value(1)->default('no')->checked(false) }} {{-- If unchecked will send "no" with request --}}

{{ BsForm::radio('name', 'value')->checked(false)->label('label') }}
{{ BsForm::radio('name')->value('value')->checked(false)->label('label') }}
```

> By default, will send default value "0" with an unchecked checkbox, if you want to disable it globally set the configuration key "laravel-bootstrap-forms.checkboxes.hasDefaultValue": true

\# Drop-Down Lists
==================

[](#-drop-down-lists)

```
{{ BsForm::select('size', ['L' => 'Large', 'S' => 'Small']) }}
{{ BsForm::select('size')->options(['L' => 'Large', 'S' => 'Small']) }}
```

Generating A Drop-Down List With Selected Default
-------------------------------------------------

[](#generating-a-drop-down-list-with-selected-default)

```
{{ BsForm::select('size')->options(['L' => 'Large', 'S' => 'Small'])->value('S') }}
```

Generating a Drop-Down List With an Empty Placeholder
-----------------------------------------------------

[](#generating-a-drop-down-list-with-an-empty-placeholder)

```
{{ BsForm::select('size')->options(['L' => 'Large', 'S' => 'Small'])->placeholder('Select Size') }}
```

Generating A Grouped List
-------------------------

[](#generating-a-grouped-list)

```
{{ BsForm::select('animal',[
         'Cats' => ['leopard' => 'Leopard'],
         'Dogs' => ['spaniel' => 'Spaniel'],
   ]) }}
```

File
----

[](#file)

```
{{ BsForm::file('attachment') }}
{{ BsForm::file('attachments')->multiple() }}
```

Base64Image (with preview)
--------------------------

[](#base64image-with-preview)

```
{{ BsForm::base64image('avatar') }}
{{ BsForm::base64image('avatar')->label('Avatar') }}
{{ BsForm::base64image('avatar')
    ->label('Avatar')
    ->uploadLabel('Upload Picture')
    ->resetLabel('Reset Picture')
    ->uploadColor('primary')
    ->resetColor('danger') }}
{{ BsForm::base64image('avatar')
    ->label('Avatar')
    ->default('/path/to/default/preview') }}
```

> Regarding upload label &amp; reset label, you can add them into translation file for the resource in `actions.{resource_name}` array, for example if the resource name is `users` and the field name is `avatar`, You should add the following translation `lang/en/users.php`:

```
