Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How to use Laravel Form Components with Bootstrap instead of Tailwind


How to use Laravel Form Components with Bootstrap instead of Tailwind


To use the protonemedia/laravel-form-components package with Bootstrap instead of Tailwind CSS, follow these steps:

1. Install the package via Composer:

bash
composer require protonemedia/laravel-form-components

2. Publish the configuration file and views:

bash
php artisan vendor:publish --provider="ProtoneMedia\LaravelFormComponents\Support\ServiceProvider"

3. In the `form-components.php` configuration file, change the `framework` setting to `bootstrap-4` or `bootstrap-5` depending on the version of Bootstrap you are using:

php
return [
    'prefix' => '',
    'framework' => 'bootstrap-4',
    'components' => [
        'form-input' => [
            'view' => 'form-components::bootstrap.form-input',
            'class' => \ProtoneMedia\LaravelFormComponents\Components\FormInput::class,
        ],
        // ... other component configurations
    ],
];

4. Now you can use the Bootstrap-specific form components in your Blade templates:

html
<x-form>
    @bind($user)
    <x-form-input name="last_name" label="Last Name" />
    <x-form-select name="country_code" :options="$options" />
    <x-form-select name="interests[]" :options="$multiOptions" label="Select your interests" multiple />
    <x-form-textarea name="biography" language="nl" placeholder="Dutch Biography" />
    <x-form-textarea name="biography" language="en" placeholder="English Biography" />
    <x-form-group name="newsletter_frequency" label="Newsletter frequency" inline>
        <x-form-radio name="newsletter_frequency" value="daily" label="Daily" />
        <x-form-radio name="newsletter_frequency" value="weekly" label="Weekly" />
    </x-form-group>
    <x-form-group>
        <x-form-checkbox name="subscribe_to_newsletter" label="Subscribe to newsletter" />
        <x-form-checkbox name="agree_terms" label="Agree with terms" />
    </x-form-group>
    <x-form-submit />
    @endbind
</x-form>

The key differences when using Bootstrap instead of Tailwind CSS are:

- The Bootstrap-specific Blade views are used (`bootstrap.form-input`, `bootstrap.form-select`, etc.)
- The Bootstrap-specific styles and classes are applied to the form elements

The package provides the same features and functionality, regardless of the CSS framework used. You can customize the Bootstrap-specific views and styles by modifying the published files in the `resources/views/vendor/form-components` directory.

Citations:
[1] https://protone.media/nl/blog/laravel-form-components-to-rapidly-build-forms-with-tailwind-css-and-bootstrap-4
[2] https://github.com/protonemedia/laravel-form-components
[3] https://github.com/bastinald/laravel-bootstrap-components
[4] https://laravel-bootstrap-components.com
[5] https://laravel-bootstrap-components.com/components/forms